Watertight ray triangle intersection

ABSTRACT

A hardware-based traversal coprocessor provides acceleration of tree traversal operations searching for intersections between primitives represented in a tree data structure and a ray. The primitives may include triangles used in generating a virtual scene. The hardware-based traversal coprocessor is configured to properly handle numerically challenging computations at or near edges and/or vertices of primitives and/or ensure that a single intersection is reported when a ray intersects a surface formed by primitives at or near edges and/or vertices of the primitives.

CROSS-REFERENCE TO RELATED PATENTS AND APPLICATIONS

This application is a continuation of U.S. patent application Ser. No.16/101,148, filed Aug. 10th, 2018, which is hereby incorporated byreference and is related to the following commonly assigned US patentsand patent applications, the entire contents of each of which areincorporated by reference: U.S. application Ser. No. 14/563,872 titled“Short Stack Traversal of Tree Data Structures” filed Dec. 8, 2014; U.S.Pat. No. 9,582,607 titled “Block-Based Bounding Volume Hierarchy”; U.S.Pat. No. 9,552,664 titled “Relative Encoding For A Block-Based BoundingVolume Hierarchy” as; U.S. Pat. No. 9,569,559 titled “Beam Tracing”filed Mar. 18, 2015; U.S. Pat. No. 10,025,879 titled “Tree DataStructures Based on a Plurality of Local Coordinate Systems”; U.S.application Ser. No. 14/737,343 titled “Block-Based Lossless Compressionof Geometric Data” filed Jun. 11, 2015; and the following USApplications filed concurrently herewith:

U.S. patent application Ser. No. 16/101,066 titled “Method for ContinuedBounding Volume Hierarchy Traversal on Intersection without ShaderIntervention”;

U.S. patent application Ser. No. 16/101,109 titled “Method for EfficientGrouping of Cache Requests for Datapath Scheduling”;

U.S. patent application Ser. No. 16/101,247 titled “A Robust, EfficientMultiprocessor-Coprocessor Interface”;

U.S. patent application Ser. No. 16/101,180 titled “Query-SpecificBehavioral Modification of Tree Traversal”;

U.S. patent application Ser. No. 16/101,196 titled “Method for HandlingOut-of-Order Opaque and Alpha Ray/Primitive Intersections”; and

U.S. patent application Ser. No. 16/101,232 titled “Method for ForwardProgress and Programmable Timeouts of Tree Traversal Mechanisms inHardware”.

FIELD

The present technology relates to computer graphics, and moreparticularly to ray tracers. More particularly, the technology relatesto hardware acceleration of computer graphics processing including butnot limited to ray tracing. Still more particularly, the examplenon-limiting technology herein relates to a hardware-based traversalcoprocessor that efficiently traverses an acceleration data structuree.g., for real time ray tracing. In still more detail, the technologyherein provides an improved hardware-based traversal coprocessor forhandling intersections at or near edges and/or vertices shared bytriangles to provide watertight ray triangle intersections.

BACKGROUND & SUMMARY

If you look around the visual scene before you, you will notice thatsome of the most interesting visual effects you see are produced bylight rays interacting with surfaces. This is because light is the onlything we see. We don't see objects—we see the light that is reflected orrefracted by the objects. Most of the objects we can see reflect light(the color of an object is determined by which parts of light the objectreflects and which parts it absorbs). Shiny surfaces such as metallicsurfaces, glossy surfaces, ceramics, the surfaces of liquids and avariety of others (even the corneas of the human eyes) act as mirrorsthat specularly reflect light. For example, a shiny metal surface willreflect light at the same angle as it hit the surface. An object canalso cast shadows by preventing light from reaching other surfaces thatare behind the object relative to a light source. If you look around,you will notice that the number and kinds of reflections and the number,kinds and lengths of shadows depend on many factors including the numberand type of lights in the scene. A single point light such as a singlefaraway light bulb will produce single reflections and hard shadows.Area light sources such as windows or light panels produce differentkinds of reflection highlights and softer shadows. Multiple lights willtypically produce multiple reflections and more complex shadows (forexample, three separated point light sources will produce three shadowswhich may overlap depending on the positions of the lights relative toan object).

If you move your head as you survey the scene, you will notice that thereflections change in position and shape (the shadows do the same). Bychanging your viewpoint, you are changing the various angles of thelight rays your eyes detect. This occurs instantaneously—you move yourhead and the visual scene changes immediately.

The simple act of drinking a cup of tea is a complex visual experience.The various shiny surfaces of the glossy ceramic cup on the table beforeyou reflect each light in the room, and the cup casts a shadow for eachlight. The moving surface of the tea in the cup is itself reflective.You can see small reflected images of the lights on the tea's surface,and even smaller reflections on the part of the tea's surface where theliquid curves up to meet the walls of the cup. The cup walls also castshadows onto the surface of the liquid in the cup. Lifting the cup toyour mouth causes these reflections and shadows to shift and shimmer asyour viewpoint changes and as the surface of the liquid is agitated bymovement.

We take these complexities of reflections and shadows for granted. Ourbrains are adept at decoding the positions, sizes and shapes of shadowsand reflections and using them as visual cues. This is in part how wediscern the position of objects relative to one another, how wedistinguish one object from another and how we learn what objects aremade of. Different object surfaces reflect differently. Specular (mirrortype) reflection of hard metal creates images of reflected objects,while diffuse reflection off of rough surfaces is responsible for colorand lights up objects in a softer way. Shadows can be soft and diffuseor hard and distinct depending on the type of lighting, and the lengthsand directions of the shadows will depend on the angle of the light raysrelative to the object and our eyes.

Beginning artists typically don't try to show reflection or shadows.They tend to draw flat scenes that have no shadows and no reflections orhighlights. The same was true with computer graphics of the past.

Real time computer graphics have advanced tremendously over the last 30years. With the development in the 1980's of powerful graphicsprocessing units (GPUs) providing 3D hardware graphics pipelines, itbecame possible to produce 3D graphical displays based on texture-mappedpolygon primitives in real time response to user input. Such real timegraphics processors were built upon a technology called scan conversionrasterization, which is a means of determining visibility from a singlepoint or perspective. Using this approach, three-dimensional objects aremodelled from surfaces constructed of geometric primitives, typicallypolygons such as triangles. The scan conversion process establishes andprojects primitive polygon vertices onto a view plane and fills in thepoints inside the edges of the primitives. See e.g., Foley, Van Dam,Hughes et al, Computer Graphics: Principles and Practice (2d Ed.Addison-Wesley 1995 & 3d Ed. Addison-Wesley 2014).

Hardware has long been used to determine how each polygon surface shouldbe shaded and texture-mapped and to rasterize the shaded, texture-mappedpolygon surfaces for display. Typical three-dimensional scenes are oftenconstructed from millions of polygons. Fast modern GPU hardware canefficiently process many millions of graphics primitives for eachdisplay frame (every 1/30^(th) or 1/60^(th) of a second) in real timeresponse to user input. The resulting graphical displays have been usedin a variety of real time graphical user interfaces including but notlimited to augmented reality, virtual reality, video games and medicalimaging. But traditionally, such interactive graphics hardware has notbeen able to accurately model and portray reflections and shadows.

Some have built other technologies onto this basic scan conversionrasterization approach to allow real time graphics systems to accomplisha certain amount of realism in rendering shadows and reflections. Forexample, texture mapping has sometimes been used to simulate reflectionsand shadows in a 3D scene. One way this is commonly done is totransform, project and rasterize objects from different perspectives,write the rasterized results into texture maps, and sample the texturemaps to provide reflection mapping, environment mapping and shadowing.While these techniques have proven to be useful and moderatelysuccessful, they do not work well in all situations. For example,so-called “environment mapping” may often require assuming theenvironment is infinitely distant from the object. In addition, anenvironment-mapped object may typically be unable to reflect itself. Seee.g.,http://developer.download.nvidia.com/CgTutorial/eg_tutorial_chapter07.html.These limitations result because conventional computer graphicshardware—while sufficiently fast for excellent polygon rendering—doesnot perform the light visualization needed for accurate and realisticreflections and shadows. Some have likened raster/texture approximationsof reflections and shadows as the visual equivalent of AM radio.

There is another graphics technology which does perform physicallyrealistic visibility determinations for reflection and shadowing. It iscalled “ray tracing”. Ray tracing was developed at the end of the 1960'sand was improved upon in the 1980's. See e.g., Apple, “Some Techniquesfor Shading Machine Renderings of Solids” (SJCC 1968) pp. 27-45;Whitted, “An Improved Illumination Model for Shaded Display” Pages343-349 Communications of the ACM Volume 23 Issue 6 (June 1980); andKajiya, “The Rendering Equation”, Computer Graphics (SIGGRAPH 1986Proceedings, Vol. 20, pp. 143-150). Since then, ray tracing has beenused in non-real time graphics applications such as design and filmmaking. Anyone who has seen “Finding Dory” (2016) or other Pixaranimated films has seen the result of the ray tracing approach tocomputer graphics—namely realistic shadows and reflections. See e.g.,Hery et al, “Towards Bidirectional Path Tracing at Pixar” (2016).

Ray tracing is a primitive used in a variety of rendering algorithmsincluding for example path tracing and Metropolis light transport. In anexample algorithm, ray tracing simulates the physics of light bymodeling light transport through the scene to compute all global effects(including for example reflections from shiny surfaces) using rayoptics. In such uses of ray tracing, an attempt may be made to traceeach of many hundreds or thousands of light rays as they travel throughthe three-dimensional scene from potentially multiple light sources tothe viewpoint. Often, such rays are traced relative to the eye throughthe scene and tested against a database of all geometry in the scene.The rays can be traced forward from lights to the eye, or backwards fromthe eye to the lights, or they can be traced to see if paths startingfrom the virtual camera and starting at the eye have a clear line ofsight. The testing determines either the nearest intersection (in orderto determine what is visible from the eye) or traces rays from thesurface of an object toward a light source to determine if there isanything intervening that would block the transmission of light to thatpoint in space. Because the rays are similar to the rays of light inreality, they make available a number of realistic effects that are notpossible using the raster based real time 3D graphics technology thathas been implemented over the last thirty years. Because eachilluminating ray from each light source within the scene is evaluated asit passes through each object in the scene, the resulting images canappear as if they were photographed in reality. Accordingly, these raytracing methods have long been used in professional graphicsapplications such as design and film, where they have come to dominateover raster-based rendering.

The main challenge with ray tracing has generally been speed. Raytracing requires the graphics system to compute and analyze, for eachframe, each of many millions of light rays impinging on (and potentiallyreflected by) each surface making up the scene. In the past, thisenormous amount of computation complexity was impossible to perform inreal time.

One reason modern GPU 3D graphics pipelines are so fast at renderingshaded, texture-mapped surfaces is that they use coherence efficiently.In conventional scan conversion, everything is assumed to be viewedthrough a common window in a common image plane and projected down to asingle vantage point. Each triangle or other primitive is sent throughthe graphics pipeline and covers some number of pixels. All relatedcomputations can be shared for all pixels rendered from that triangle.Rectangular tiles of pixels corresponding to coherent lines of sightpassing through the window may thus correspond to groups of threadsrunning in lock-step in the same streaming processor. All the pixelsfalling between the edges of the triangle are assumed to be the samematerial running the same shader and fetching adjacent groups of texelsfrom the same textures. In ray tracing, in contrast, rays may start orend at a common point (a light source, or a virtual camera lens) but asthey propagate through the scene and interact with different materials,they quickly diverge. For example, each ray performs a search to findthe closest object. Some caching and sharing of results can beperformed, but because each ray potentially can hit different objects,the kind of coherence that GPU's have traditionally taken advantage ofin connection with texture mapped, shaded triangles is not present(e.g., a common vantage point, window and image plane are not there forray tracing). This makes ray tracing much more computationallychallenging than other graphics approaches—and therefore much moredifficult to perform on an interactive basis.

Much research has been done on making the process of tracing rays moreefficient and timely. See e.g., Glassner, An Introduction to Ray Tracing(Academic Press Inc., 1989). Because each ray in ray tracing is, by itsnature, evaluated independently from the rest, ray tracing has beencalled “embarrassingly parallel.” See e.g., Akenine-Möller et al., RealTime Rendering at Section 9.8.2, page 412 (Third Ed. CRC Press 2008). Asdiscussed above, ray tracing involves effectively testing each rayagainst all objects and surfaces in the scene. An optimization called“acceleration data structure” and associated processes allows thegraphics system to use a “divide-and-conquer” approach across theacceleration data structure to establish what surfaces the ray hits andwhat surfaces the ray does not hit. Each ray traverses the accelerationdata structure in an individualistic way. This means that dedicatingmore processors to ray tracing gives a nearly linear performanceincrease. With increasing parallelism of graphics processing systems,some began envisioning the possibility that ray tracing could beperformed in real time. For example, work at Saarland University in themid-2000's produced an early special purpose hardware system forinteractive ray tracing that provided some degree of programmability forusing geometry, vertex and lighting shaders. See Woop et al., “RPU: AProgrammable Ray Processing Unit for Real Time Ray Tracing” (ACM 2005).As another example, Advanced Rendering Technology developed“RenderDrive” based on an array of AR250/350 rendering processorsderived from ARM1 and enhanced with custom pipelines for ray/triangleintersection and SIMD vector and texture math but with no fixed-functiontraversal logic. See e.g.,http://www.graphicshardware.org/previous/www_2001/presentations/Hot3D_Daniel_Hall.pdf

Then, in 2010, NVIDIA took advantage of the high degree of parallelismof NVIDIA GPUs and other highly parallel architectures to develop theOptiX™ ray tracing engine. See Parker et al., “OptiX: A General PurposeRay Tracing Engine” (ACM Transactions on Graphics, Vol. 29, No. 4,Article 66, July 2010). In addition to improvements in API's(application programming interfaces), one of the advances provided byOptiX™ was improving the acceleration data structures used for findingan intersection between a ray and the scene geometry. Such accelerationdata structures are usually spatial or object hierarchies used by theray tracing traversal algorithm to efficiently search for primitivesthat potentially intersect a given ray. OptiX™ provides a number ofdifferent acceleration structure types that the application can choosefrom. Each acceleration structure in the node graph can be a differenttype, allowing combinations of high-quality static structures withdynamically updated ones.

The OptiX™ programmable ray tracing pipeline provided significantadvances, but was still generally unable by itself to provide real timeinteractive response to user input on relatively inexpensive computingplatforms for complex 3D scenes. Since then, NVIDIA has been developinghardware acceleration capabilities for ray tracing. See e.g., U.S. Pat.Nos. 9,582,607; 9,569,559; US20160070820; and US20160070767.

Given the great potential of a truly interactive real time ray tracinggraphics processing system for rendering high quality images ofarbitrary complexity in response for example to user input, further workis possible and desirable.

Some Ray Processes Can Provide Incorrect Results or May be Limited toSoftware Implementations

Ray tracing needs to resolve ray intersections when a ray passes atedges and/or vertices shared by triangles. At these locations incorrectresults may be provided when, for example, an intersection is notidentified or multiple incorrect intersections are identified. ARay/Triangle Test data pipe that attempts to resolve ray intersectionswith edges shared between triangles is known. See e.g., Woop et al,“Watertight Ray/Triangle Intersection”, Journal of Computer GraphicsTechniques Vol. 2, No. 1, 2013 (2013), which is hereby incorporated byreference. Such implementations were designed for software ray tracingon a CPU, and fall back to double precision whenever one of thebarycentric coordinates is zero-valued. For example, single precision isused to obtain first results and if the first result could be consideredto not be correct or precise then a second calculation using doubleprecision is performed. The technique of Woop et al. also yieldsmultiple reported intersections when ray passes exactly through an edgeor a vertex, which is traditionally avoided in rasterization-basedgraphics. However, accelerator hardware may not have double precisioncomputation capabilities. Therefore, further improvements are possibleand desirable.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates an example non-limiting ray tracing graphics system.

FIG. 2A shows an example specular object.

FIG. 2B shows the example object within a bounding volume.

FIG. 2C shows an example volumetric subdividing of the FIG. 2B boundingvolume.

FIGS. 2D, 2E and 2F show example further levels of volumetricsubdivision of the bounding volume to create a bounding volume hierarchy(BVH).

FIG. 2G shows an example portion of the object comprised of primitivesurfaces, in this case triangles.

FIGS. 3A-3C show example simplified ray tracing tests to determinewhether the ray passes through a bounding volume containing geometry andwhether the ray intersects geometry.

FIG. 4 illustrates an example ray tracing flowchart.

FIGS. 5A-5C show example different ray-primitive intersection scenarios.

FIGS. 6A and 6B show an example of how texture mapping can impactray-primitive intersection results.

FIGS. 7A and 7B illustrate ray instance transforms.

FIG. 8A illustrates an example non-limiting bounding volume hierarchy(BVH).

FIG. 8B shows an example acceleration data structure in the form of agraph or tree.

FIG. 9 shows a simplified example non-limiting traversal co-processorcomprising a tree traversal unit (TTU).

FIG. 10A illustrates an example non-limiting ray tracing shadingpipeline flowchart.

FIGS. 10B and 10C illustrate more detailed ray tracing pipelines.

FIG. 11A illustrates a ray going exactly through an edge (in post-shearcoordinates) without entering a box.

FIG. 11B illustrates an example non-limiting method for determiningray-primitives intersections.

FIG. 12 shows an example non-limiting process for determiningintersections between a ray and one or more triangles.

FIG. 13 shows a single-precision floating-point representation andexpanded exponent single-precision floating-point representation.

FIG. 14 illustrates an example non-limiting ray-triangle intersectiontest providing a single hit return for a closed mesh.

FIG. 15 illustrates an example non-limiting ray-triangle test andtransform unit.

FIG. 16A illustrates a tie-breaking scheme obtained from following hitpatterns for edges.

FIG. 16B illustrates a triangle fan with vertex shared at the origin bya plurality of triangles.

FIG. 17 illustrates an example flowchart for generating an image.

FIG. 18 illustrates an example parallel processing unit (PPU).

FIG. 19 illustrates an example memory partition unit.

FIG. 20 illustrates an example general processing cluster (GPC) withinthe parallel processing unit of FIG. 18.

FIG. 21 is a conceptual diagram of a graphics processing pipelineimplemented by the GPC of FIG. 20.

FIGS. 22 and 23 illustrate an example streaming multi-processor.

FIG. 24 is a conceptual diagram of a processing system implemented usingPPUs of FIG. 18.

FIG. 25 expands FIG. 24 to show additional interconnected devices.

DETAILED DESCRIPTION OF NON-LIMITING EMBODIMENTS

The technology herein provides hardware capabilities that accelerate raytracing to such an extent that it brings the power of ray tracing togames and other interactive real time computer graphics, initiallyenabling high effect quality in shadows and reflections and ultimatelyglobal illumination. In practice, this means accelerating ray tracing bya factor of up to an order of magnitude or more over what would bepossible in software on the same graphics rendering system.

In more detail, the example non-limiting technology provides dedicatedhardware to accelerate ray tracing. In non-limiting embodiments, ahardware co-processor (herein referred to as a “traversal coprocessor”or in some embodiments a “tree traversal unit” or “TTU”) acceleratescertain processes supporting interactive ray tracing includingray-bounding volume intersection tests, ray-primitive intersection testsand ray “instance” transforms.

In some non-limiting embodiments, the traversal co-processor performsqueries on an acceleration data structure for processes running onpotentially massively-parallel streaming multiprocessors (SMs). Thetraversal co-processor traverses the acceleration data structure todiscover information about how a given ray interacts with an object theacceleration data structure describes or represents. For ray tracing,the traversal coprocessors are callable as opposed to e.g., fixedfunction units that perform an operation once between logical pipelinestages running different types of threads (e.g., vertex threads andpixel threads).

In some non-limiting embodiments, the acceleration data structurecomprises a hierarchy of bounding volumes (bounding volume hierarchy orBVH) that recursively encapsulates smaller and smaller bounding volumesubdivisions. The largest volumetric bounding volume may be termed a“root node.” The smallest subdivisions of such hierarchy of boundingvolumes (“leaf nodes”) contain items. The items could be primitives(e.g., polygons such as triangles) that define surfaces of the object.Or, an item could be a sphere that contains a whole new level of theworld that exists as an item because it has not been added to the BVH(think of the collar charm on the cat from “Men in Black” whichcontained an entire miniature galaxy inside of it). If the itemcomprises primitives, the traversal co-processor tests rays against theprimitives to determine which object surfaces the rays intersect andwhich object surfaces are visible along the ray.

The traversal co-processor performs a test of each ray against a widerange of bounding volumes, and can cull any bounding volumes that don'tintersect with that ray. Starting at a root node that bounds everythingin the scene, the traversal co-processor tests each ray against smaller(potentially overlapping) child bounding volumes which in turn bound thedescendent branches of the BVH. The ray follows the child pointers forthe bounding volumes the ray hits to other nodes until the leaves orterminal nodes (volumes) of the BVH are reached. Once the traversalco-processor traverses the acceleration data structure to reach aterminal or “leaf” node that contains a geometric primitive, it performsan accelerated ray-primitive intersection test that determines whetherthe ray intersects that primitive (and thus the object surface thatprimitive defines). The ray-primitive test can provide additionalinformation about primitives the ray intersects that can be used todetermine the material properties of the surface required for shadingand visualization. Recursive traversal through the acceleration datastructure enables the traversal co-processor to discover all objectprimitives the ray intersects, or the closest (from the perspective ofthe viewpoint) primitive the ray intersects (which in some cases is theonly primitive that is visible from the viewpoint along the ray).

The traversal co-processor also accelerates the transform of each rayfrom world space into object space to obtain finer and finer boundingbox encapsulations of the primitives and reduce the duplication of thoseprimitives across the scene. Objects replicated many times in the sceneat different positions, orientations and scales can be represented inthe scene as instance nodes which associate a bounding box and leaf nodein the world space BVH with a transformation that can be applied to theworld-space ray to transform it into an object coordinate space, and apointer to an object-space BVH. This avoids replicating the object spaceBVH data multiple times in world space, saving memory and associatedmemory accesses. The instance transform increases efficiency bytransforming the ray into object space instead of requiring the geometryor the bounding volume hierarchy to be transformed into world (ray)space and is also compatible with additional, conventional rasterizationprocesses that graphics processing performs to visualize the primitives.

The presently disclosed non-limiting embodiments thus provide atraversal co-processor, a new subunit of one or a group of streamingmultiprocessor SMs of a 3D graphics processing pipeline. In order tounderstand where the traversal co-processor fits in the overall picture,it may be helpful to understand a few fundamentals of the algorithmemployed by most or all modern ray tracers. But it should be pointed outthat the technology herein provides a generic capability to determine,for a thread running in a GPU, what the nearest visible thing is from agiven point along a specified direction, or if anything lies between twopoints. A common use case for such capability will be in processes thatstart tracing rays from points that have already been rasterized ontriangles using conventional scan conversion techniques. The disclosedtechnology can but does not necessarily replace or substitute for scanconversion technology, and may often augment it and be used inconjunction with scan conversion techniques to enhance images withphotorealistic reflections, shadows and other effects.

Ray Tracing Techniques

Generally, ray tracing is a rendering method in which rays are used todetermine the visibility of various elements in the scene. Ray tracingcan be used to determine if anything is visible along a ray (forexample, testing for occluders between a shaded point on a geometricprimitive and a point on a light source) and can also be used toevaluate reflections (which may for example involve performing atraversal to determine the nearest visible surface along a line of sightso that software running on a streaming processor can evaluate amaterial shading function corresponding to what was hit—which in turncan launch one or more additional rays into the scene according to thematerial properties of the object that was intersected) to determine thelight returning along the ray back toward the eye. In classicalWhitted-style ray tracing, rays are shot from the viewpoint through thepixel grid into the scene, but other path traversals are possible.Typically, for each ray, the closest object is found. This intersectionpoint can then be determined to be illuminated or in shadow by shootinga ray from it to each light source in the scene and finding if anyobjects are in between. Opaque objects block the light, whereastransparent objects attenuate it. Other rays can be spawned from anintersection point. For example, if the intersecting surface is shiny orspecular, rays are generated in the reflection direction. The ray mayaccept the color of the first object intersected, which in turn has itsintersection point tested for shadows. This reflection process isrecursively repeated until a recursion limit is reached or the potentialcontribution of subsequent bounces falls below a threshold. Rays canalso be generated in the direction of refraction for transparent solidobjects, and again recursively evaluated. See Akenine-Möller et al.,cited above. Ray tracing technology thus allows a graphics system todevelop physically correct reflections and shadows that are not subjectto the limitations and artifacts of scan conversion techniques.

Traversal Coprocessor

The basic task the traversal coprocessor performs is to test a rayagainst all primitives (commonly triangles in one embodiment) in thescene and report either the closest hit (according to distance measuredalong the ray) or simply the first (not necessarily closest) hitencountered, depending upon use case. The naïve algorithm would be anO(n) brute-force search. By pre-processing the scene geometry andbuilding a suitable acceleration data structure in advance, however, itis possible to reduce the average-case complexity to O(log n). In raytracing, the time for finding the closest (or for shadows, any)intersection for a ray is typically order O(log n) for n objects when anacceleration data structure is used. For example, bounding volumehierarchies (BVHs) of the type commonly used for modern ray tracingacceleration data structures typically have an O(log n) search behavior.

Bounding Volume Hierarchies

The acceleration data structure most commonly used by modern ray tracersis a bounding volume hierarchy (BVH) comprising nested axis-alignedbounding boxes (AABBs). The leaf nodes of the BVH contain the primitives(e.g., triangles) to be tested for intersection. The BVH is most oftenrepresented by a graph or tree structure data representation. In suchinstances, the traversal coprocessor may be called a “tree traversalunit” or “TTU”.

Given a BVH, ray tracing amounts to a tree search where each node in thetree visited by the ray has a bounding volume for each descendent branchor leaf, and the ray only visits the descendent branches or leaves whosecorresponding bound volume it intersects. In this way, only a smallnumber of primitives must be explicitly tested for intersection, namelythose that reside in leaf nodes intersected by the ray. In the examplenon-limiting embodiments, the traversal coprocessor accelerates bothtree traversal (including the ray-volume tests) and ray-primitive tests.As part of traversal, the traversal coprocessor can also handle“instance transforms”—transforming a ray from world-space coordinatesinto the coordinate system of an instanced mesh (object space) e.g., inorder to avoid the computational complexity of transforming theprimitive vertices into world space. It can do so in a MIMD(multiple-instruction, multiple data) fashion, meaning that the rays arehandled independently once inside the traversal coprocessor.

Example Non-Limiting Real Time Interactive Ray Tracing System

FIG. 1 illustrates an example real time ray interactive tracing graphicssystem 100 for generating images using three dimensional (3D) data of ascene or object(s). System 100 includes an input device 110, aprocessor(s) 120, a graphics processing unit(s) (GPU(s)) 130, memory140, and a display(s) 150. The system shown in FIG. 1 can take on anyform factor including but not limited to a personal computer, a smartphone or other smart device, a video game system, a wearable virtual oraugmented reality system, a cloud-based computing system, avehicle-mounted graphics system, a system-on-a-chip (SoC), etc.

The processor 120 may be a multicore central processing unit (CPU)operable to execute an application in real time interactive response toinput device 110, the output of which includes images for display ondisplay 150. Display 150 may be any kind of display such as a stationarydisplay, a head mounted display such as display glasses or goggles,other types of wearable displays, a handheld display, a vehicle mounteddisplay, etc. For example, the processor 120 may execute an applicationbased on inputs received from the input device 110 (e.g., a joystick, aninertial sensor, an ambient light sensor, etc.) and instruct the GPU 130to generate images showing application progress for display on thedisplay 150.

Based on execution of the application on processor 120, the processormay issue instructions for the GPU 130 to generate images using 3D datastored in memory 140. The GPU 130 includes specialized hardware foraccelerating the generation of images in real time. For example, the GPU130 is able to process information for thousands or millions of graphicsprimitives (polygons) in real time due to the GPU's ability to performrepetitive and highly-parallel specialized computing tasks such aspolygon scan conversion much faster than conventional software-drivenCPUs. For example, unlike the processor 120, which may have multiplecores with lots of cache memory that can handle a few software threadsat a time, the GPU 130 may include hundreds or thousands of processingcores or “streaming multiprocessors” (SMs) 132 running in parallel.

In one example embodiment, the GPU 130 includes a plurality ofprogrammable streaming multiprocessors (SMs) 132, and a hardware-basedgraphics pipeline including a graphics primitive engine 134 and a rasterengine 136. These components of the GPU 130 are configured to performreal-time image rendering using a technique called “scan conversionrasterization” to display three-dimensional scenes on a two-dimensionaldisplay 150. In rasterization, geometric building blocks (e.g., points,lines, triangles, quads, meshes, etc.) of a 3D scene are mapped topixels of the display (often via a frame buffer memory).

The GPU 130 converts the geometric building blocks (i.e., polygonprimitives such as triangles) of the 3D model into pixels of the 2Dimage and assigns an initial color value for each pixel. The graphicspipeline may apply shading, transparency, texture and/or color effectsto portions of the image by defining or adjusting the color values ofthe pixels. The final pixel values may be anti-aliased, filtered andprovided to the display 150 for display. Many software and hardwareadvances over the years have improved subjective image quality usingrasterization techniques at frame rates needed for real-time graphics(i.e., 30 to 60 frames per second) at high display resolutions such as4096×2160 pixels or more on one or multiple displays 150.

Traversal Coprocessor Addition to Architecture

To enable the GPU 130 to perform ray tracing in real time in anefficient manner, the GPU is provided with traversal coprocessor 138coupled to one or more SMs 132. The traversal coprocessor 138 includeshardware components configured to perform operations commonly utilizedin ray tracing algorithms. A goal of the traversal coprocessor 138 is toaccelerate operations used in ray tracing to such an extent that itbrings the power of ray tracing to real-time graphics application (e.g.,games), enabling high-quality shadows, reflections, and globalillumination. As discussed in more detail below, the result of thetraversal coprocessor 138 may be used together with or as an alternativeto other graphics related operations performed in the GPU 130.

In the example architecture shown, the new hardware component called a“traversal coprocessor” 138 is used to accelerate certain tasksincluding but not limited to ray tracing. Ray tracing refers to castinga ray into a scene and determining whether and where that ray intersectsthe scene's geometry. This basic ray tracing visibility test is thefundamental primitive underlying a variety of rendering algorithms andtechniques in computer graphics. For example, ray tracing can be usedtogether with or as an alternative to rasterization and z-buffering forsampling scene geometry. It can also be used as an alternative to (or incombination with) environment mapping and shadow texturing for producingmore realistic reflection, refraction and shadowing effects than can beachieved via texturing techniques or other raster “hacks”. To overcomelimitations in image quality that can be achieved with rasterization,system 100 can also generate entire images or parts of images using raytracing techniques. Ray tracing may also be used as the basic primitiveto accurately simulate light transport in physically-based renderingalgorithms such as path tracing, photon mapping, Metropolis lighttransport, and other light transport algorithms.

More specifically, SMs 132 and the traversal coprocessor 138 maycooperate to cast rays into a 3D model and determine whether and wherethat ray intersects the model's geometry. Ray tracing directly simulateslight traveling through a virtual environment or scene. The results ofthe ray intersections together with surface texture, viewing direction,and/or lighting conditions are used to determine pixel color values. Raytracing performed by SMs 132 working with traversal coprocessor 138allows for computer-generated images to capture shadows, reflections,and refractions in ways that can be indistinguishable from photographsor video of the real world. Since ray tracing techniques are even morecomputationally intensive than rasterization due in part to the largenumber of rays that need to be traced, the traversal coprocessor 138 iscapable of accelerating in hardware certain of the morecomputationally-intensive aspects of that process.

In the example non-limiting technology herein, traversal coprocessor 138accelerates both ray-box tests and ray-primitive tests. As part oftraversal, it can also handle at least one level of instance transforms,transforming a ray from world-space coordinates into the coordinatesystem of an instanced mesh. In the example non-limiting embodiments,the traversal coprocessor 138 does all of this in MIMD fashion, meaningthat rays are handled independently once inside the traversalcoprocessor.

In the example non-limiting embodiments, the traversal coprocessor 138operates as a servant (coprocessor) to the SMs (streamingmultiprocessors) 132. In other words, the traversal coprocessor 138 inexample non-limiting embodiments does not operate independently, butinstead follows the commands of the SMs 132 to perform certaincomputationally-intensive ray tracing related tasks much moreefficiently than the SMs 132 could perform themselves.

In the examples shown, the traversal coprocessor 138 receives commandsvia SM 132 instructions and writes results back to an SM register file.For many common use cases (e.g., opaque triangles with at most one levelof instancing), the traversal coprocessor 138 can service the raytracing query without further interaction with the SM 132. Morecomplicated queries (e.g., involving alpha-tested triangles, primitivesother than triangles, or multiple levels of instancing) may requiremultiple round trips. In addition to tracing rays, the traversalcoprocessor 138 is capable of performing more general spatial querieswhere an AABB or the extruded volume between two AABBs (which we call a“beam”) takes the place of the ray. Thus, while the traversalcoprocessor 138 is especially adapted to accelerate ray tracing relatedtasks, it can also be used to perform tasks other than ray tracing.

In addition to the traversal coprocessor 138, the example non-limitingtechnology used to support the system 100 of FIG. 1 provides additionalaccelerated ray tracing enhancements to a number of units as well as asubstantial effort devoted to BVH construction. BVH construction neednot be hardware accelerated (although it may be in some non-limitingembodiments) but could instead be implemented using highly-optimizedsoftware routines running on SMs 132 and/or CPU 120 and/or otherdevelopment systems e.g., during development of an application. Thefollowing exposition describes, among other things, software-visiblebehavior of the traversal coprocessor 138, interfaces to surroundingunits (SMs 132 and the memory subsystem), and additional features thatare part of a complete ray-tracing solution such as certain enhancementsto the group of SMs 132 and the memory caching system.

In example non-limiting embodiments, the traversal coprocessor 138allows for quick traversal of an accelerated data structure (e.g., aBVH) to determine which primitives (e.g., triangles used for generatinga scene) in the data structure are intersected by a query data structure(e.g., a ray). The traversal coprocessor 138 provides solutions forproblems related to the practice of TTU-accelerated ray-traced renderingin a software application running on a GPU. Exemplary non-limitingembodiments of this disclosure, may extend, for example, the TreeTraversal Unit (TTU) described in U.S. Pat. No. 9,582,607 and the beamtracing method described in U.S. Pat. No. 9,569,559 to supportmid-traversal ray/triangle intersection such that triangles can behandled directly by the TTU without requiring SM intervention, thusavoiding frequent costly synchronizations which may be needed withoutexemplary non-limiting embodiments of this disclosure. U.S. Pat. Nos.9,582,607 and 9,569,559 are incorporated by reference.

In the example non-limiting embodiments, the TTU provides many novelaspects of the design of this datapath to ensure that the ray-triangleintersections and the resulting shaded images are robust in the face ofnumerically challenging inputs. To deliver a robust solution, thedesigns set out to provide:

-   -   Watertight edge test—a ray cannot miss a pair of triangles that        share a common edge by passing between them “through” the shared        edge.    -   Single hit—a ray that approaches an edge shared by two triangles        should not accidentally report an intersection with both        triangles.    -   Watertight vertex test—a ray cannot miss a plurality of        triangles that share a common vertex by passing between them        “through” the shared vertex.    -   Vertex single hit—a ray that approaches a vertex shared by a        plurality of triangles should not accidentally report an        intersection with multiple triangles sharing the vertex.

Exemplary non-limiting embodiments of this disclosure improve raytracing performance without compromising image quality. By supportingaccelerated ray/triangle intersection during traversal, the TTU is ableto offload a substantial amount of computation from the streamingprocessors and avoid an expensive synchronization performance penalty.Because real-time ray tracing must provide as good or better imagequality and stability as real-time rasterization, it is important thatthe TTU's ray-triangle intersection exhibits the properties ofwatertightness, conservatism, and single-hit. Exemplary non-limitingembodiments of this disclosure allow for real-time ray tracing to beapplied in real-time games employing millions of triangles.

Traversing an Acceleration Data Structure

A good way to accelerate ray tracing is to use an acceleration datastructure. The acceleration data structure represents the 3D model of anobject or a scene in a manner that will help assist in quickly decidingwhich portion of the object a particular ray is likely to intersect andquickly rejecting large portions of the scene the ray will notintersect. A bounding volume hierarchy (BVH) data structure is one typeof acceleration data structure which can help reduce the number ofintersections to test. The BVH data structure represents a scene orobject with a bounding volume and subdivides the bounding volume intosmaller and smaller bounding volumes terminating in leaf nodescontaining geometric primitives. The bounding volumes are hierarchical,meaning that the topmost level encloses the level below it, that levelencloses the next level below it, and so on. In one embodiment, leafnodes can potentially overlap other leaf nodes in the bounding volumehierarchy.

To illustrate how a bounding volume hierarchy works, FIGS. 2A-2G show ateapot recursively subdivided into smaller and smaller hierarchicalbounding volumes. FIG. 2A shows a teapot object, and FIG. 2B shows abounding volume 202 (in this case a box, cube or rectangularparallelepiped) enclosing the whole teapot. The bounding volume 202,which can be efficiently defined by its vertices, provides an indicationof the spatial location of the object and is typically dimensioned to bejust slightly larger than the object.

The first stage in acceleration structure construction acquires thebounding boxes of the referenced geometry. This is achieved by executingfor each geometric primitive in an object a bounding box procedure thatreturns a conservative axis-aligned bounding box for its input primitivesuch as box 202 shown in FIG. 2B. Using these bounding boxes aselementary primitives for the acceleration structures provides thenecessary abstraction to trace rays against arbitrary user-definedgeometry (including several types of geometry within a singlestructure). Because in FIG. 2B the bounding volume 202 is larger thanand completely contains the teapot, a ray that does not intersectbounding volume cannot intersect the teapot, although a ray that doesintersect the bounding volume may or may not intersect the teapot.Because the bounding volume 202 is readily defined by the x,y,zcoordinates of its vertices in 3D space and a ray is defined by itsx,y,z coordinates in 3D space, the ray-bounding volume test to determinewhether a ray intersects the bounding volume 202 is straightforward(although some transform may be used to adjust to different coordinatesystems, as will be explained below).

FIG. 2C, shows the bounding volume 202 subdivided into smaller containedbounding volumes. While the subdivision scheme shown here for purposesof illustration is a so-called 8-ary subdivision or “octree” in whicheach volume is subdivided into eight smaller volumes of uniform size,many other spatial hierarchies and subdivision schemes are known such asa binary tree, a four-ary tree, a k-d tree, a binary space partitioning(BSP) tree, and a bounding volume hierarchy (BVH) tree. See e.g., U.S.Pat. No. 9,582,607.

Each of the subdivided bounding volumes shown in FIG. 2C can be stillfurther subdivided. FIG. 2D shows one of the subdivided volumes 204 ofFIG. 2C being further subdivided to provide additional subdividedencapsulated bounding volumes. As shown in FIG. 2D, some of thesubdivided bounding volumes include portions of the teapot and some donot. Volumes that do not contain a portion of the teapot are not furthersubdivided because the further subdivisions provide no further spatialinformation about the teapot. Already subdivided bounding volumes thatdo include at least one portion of the teapot can be still furtherrecursively subdivided—like the emergence of each of a succession oflittler and littler cats from the hats of Dr. Seuss's' The Cat In TheHat Comes Back (1958). The portions of the space within bounding volume202 that contain geometry are recursively subdivided to permit thetraversal coprocessor 138 to use the volumetric subdivisions toefficiently discover where the geometry is located relative to any givenray. It can be noted that while a spatial or active subdivision of thevolume is possible, many implementations will create the hierarchicalstructure defining volumes and subvolumes ahead of time. In such cases,the builder may often build the hierarchy up from individual trianglesand not down from the whole scene. Building up means you do not need todetermine if some subdivided volume contains anything since bydefinition it contains what is below it in a hierarchy of volumetricsubdivisions.

FIG. 2E shows a further such subdivision of bounding volume 204 into afurther smaller contained bounding volume 206 containing in this examplejust the spout of the teapot plus another surface on the wall of theteapot, and FIG. 2F shows an additional subdivision of bounding volume206 into still smaller contained subdivision 208 encapsulating the endof the teapot's spout. Depending on the way the BVH is constructed,bounding volume 208 can be further and further subdivided as desired—andtraversal coprocessor 138 enables the FIG. 1 system 100 to efficientlytraverse the BVH down to any arbitrary subdivision level. The number andconfigurations of recursive subdivisions will depend on the complexityand configuration of the 3D object being modeled as well as otherfactors such as desired resolution, distance of the object from theviewpoint, etc.

At some level of subdivision (which can be different levels fordifferent parts of the BVH), the traversal coprocessor 138 encountersgeometry making up the encapsulated object being modeled. Using theanalogy of a tree, the successive volumetric subdivisions are the trunk,branches, boughs and twigs, and the geometric is finally revealed at thevery tips of the tree, namely the leaves. In this case, FIG. 2G showsthe surface of the teapot's spout defined by an example mesh ofgeometric primitives. The geometric primitives shown are triangles butother geometric primitives, such as quads, lines, rectangles, quadrics,patches, or other geometric primitives known to those familiar with thestate of the art, may be used (in one embodiment, such other types ofprimitives may be expressed as or converted into triangles). Thegeometric primitives in the mesh represent the shape of the 3D surfaceof the object being modeled. The example shown here is a mesh, butbounded geometry can include discontinuous geometry such as particlesthat may not be connected. In the example non-limiting embodiments, thetraversal coprocessor 138 also accelerates ray intersection tests withthis geometry to quickly determine which triangles are hit by any givenray. Determining ray-primitive intersections involves comparing thespatial xyz coordinates of the vertices of each primitive with the xyzcoordinates of the ray to determine whether the ray and the surface theprimitive defines occupy the same space. The ray-primitive intersectiontest can be computationally intensive because there may be manytriangles to test. For example, in the mesh shown in FIG. 2G, the spoutof the teapot alone is made up of over a hundred triangles—although itmay be more efficient in some implementations to further volumetricallysubdivide and thereby limit the number of triangles in any such “leafnode” to something like 16 or fewer.

As discussed above, ray tracing procedures determine what geometricprimitives of a scene are intersected by a ray. However, due to thelarge number of primitives in a 3D scene, it may not be efficient orfeasible to test every geometric primitive for an intersection.Acceleration data structures, such as BVH, allow for quick determinationas to which bounding volumes can be ignored, which bounding volumes maycontain intersected geometric primitives, and which intersectedgeometric primitives matter for visualization and which do not.

Ray Intersection Testing

FIGS. 3A-3C illustrate ray tracing applied to the FIG. 2G boundingvolume 208 including triangle mesh 320. FIG. 3A shows a ray 302 in avirtual space including bounding volumes 310 and 315. To determinewhether the ray 302 intersects one or more triangles in the mesh 320,each triangle could be directly tested against the ray 302. But toaccelerate the process (since the object could contain many thousands oftriangles), the ray 302 is first tested against the bounding volumes 310and 315. If the ray 302 does not intersect a bounding volume, then itdoes not intersect any triangles inside of the bounding volume and alltriangles inside the bounding volume can be ignored for purposes of thatray. Because in FIG. 3A the ray 302 misses bounding volume 310, thetriangles of mesh 320 within that bounding volume need not be tested forintersection. While bounding volume 315 is intersected by the ray 302,bounding volume 315 does not contain any geometry and so no furthertesting is required.

On the other hand, if a ray such as ray 304 shown in FIG. 3B intersectsa bounding volume 310 that contains geometry, then the ray may or maynot intersect the geometry inside of the bounding volume so furthertests need to be performed on the geometry itself to find possibleintersections. Because the rays 304, 306 in FIGS. 3B and 3C intersect abounding volume 310 that contains geometry, further tests need to beperformed to determine whether any (and which) of the primitives insideof the bounding volume are intersected. In FIG. 3B, further testing ofthe intersections with the primitives would indicate that even thoughthe ray 304 passes through the bounding volume 310, it does notintersect any of the primitives the bounding volume encloses(alternatively, as mentioned above, bounding volume 310 could be furthervolumetrically subdivided so that a bounding volume intersection testcould be used to reveal that the ray does not intersect any geometry ormore specifically which primitives the ray may intersect).

FIG. 3C shows a situation in which the bounding volume 310 intersectedby ray 306 and contains geometry that ray 306 intersects. Traversalcoprocessor 138 tests the intersections between the ray 306 and theindividual primitives to determine which primitives the ray intersects.

Ray Tracing Operations

FIG. 4 is a flowchart summarizing example ray tracing operations thetraversal coprocessor 138 performs as described above in cooperationwith SM(s) 132. The FIG. 4 operations are performed by traversalcoprocessor 138 in cooperation with its interaction with an SM 132. Thetraversal coprocessor 138 may thus receive the identification of a rayfrom the SM 132 and traversal state enumerating one or more nodes in oneor more BVH's that the ray must traverse. The traversal coprocessor 138determines which bounding volumes of a BVH data structure the rayintersects (the “ray-complet” test 512) and subsequently whether the rayintersects one or more primitives in the intersected bounding volumesand which triangles are intersected (the “ray-primitive test” 520). Inexample non-limiting embodiments, “complets” (compressed treelets)specify root or interior nodes (i.e., volumes) of the bounding volumehierarchy with children that are other complets or leaf nodes of asingle type per complet.

First, the traversal coprocessor 138 inspects the traversal state of theray. If a stack the traversal coprocessor 138 maintains for the ray isempty, then traversal is complete. If there is an entry on the top ofthe stack, the traversal co-processor 138 issues a request to the memorysubsystem to retrieve that node. The traversal co-processor 138 thenperforms a bounding box test 512 to determine if a bounding volume of aBVH data structure is intersected by a particular ray the SM 132specifies (step 512, 514). If the bounding box test determines that thebounding volume is not intersected by the ray (“No” in step 514), thenthere is no need to perform any further testing for visualization andthe traversal coprocessor 138 can return this result to the requestingSM 132. This is because if a ray misses a bounding volume (as in FIG. 3Awith respect to bounding volume 310), then the ray will miss all othersmaller bounding volumes inside the bounding volume being tested and anyprimitives that bounding volume contains.

If the bounding box test performed by the traversal coprocessor 138reveals that the bounding volume is intersected by the ray (“Yes” inStep 514), then the traversal coprocessor determines if the boundingvolume can be subdivided into smaller bounding volumes (step 518). Inone example embodiment, the traversal coprocessor 138 isn't necessarilyperforming any subdivision itself. Rather, each node in the BVH has oneor more children (where each child is a leaf or a branch in the BVH).For each child, there is a bounding volume and a pointer that leads to abranch or a leaf node. When a ray processes a node using traversalcoprocessor 138, it is testing itself against the bounding volumes ofthe node's children. The ray only pushes stack entries onto its stackfor those branches or leaves whose representative bounding volumes werehit. When a ray fetches a node in the example embodiment, it doesn'ttest against the bounding volume of the node—it tests against thebounding volumes of the node's children. The traversal coprocessor 138pushes nodes whose bounding volumes are hit by a ray onto the ray'straversal stack in an order determined by ray configuration. Forexample, it is possible to push nodes onto the traversal stack in theorder the nodes appear in memory, or in the order that they appear alongthe length of the ray, or in some other order. If there are furthersubdivisions of the bounding volume (“Yes” in step 518), then thosefurther subdivisions of the bounding volume are accessed and thebounding box test is performed for each of the resulting subdividedbounding volumes to determine which subdivided bounding volumes areintersected by the ray and which are not. In this recursive process,some of the bounding volumes may be eliminated by test 514 while otherbounding volumes may result in still further and further subdivisionsbeing tested for intersection by traversal coprocessor 138 recursivelyapplying steps 512-518.

Once the traversal coprocessor 138 determines that the bounding volumesintersected by the ray are leaf nodes (“No” in step 518), the traversalcoprocessor performs a primitive (e.g., triangle) intersection test 520to determine whether the ray intersects primitives in the intersectedbounding volumes and which primitives the ray intersects. The traversalcoprocessor 138 thus performs a depth-first traversal of intersecteddescendent branch nodes until leaf nodes are reached. The traversalcoprocessor 138 processes the leaf nodes. If the leaf nodes areprimitive ranges, the traversal coprocessor 138 tests them against theray. If the leaf nodes are instance nodes, the traversal coprocessor 138applies the instance transform. If the leaf nodes are item ranges, thetraversal coprocessor 138 returns them to the requesting SM 132. In theexample non-limiting embodiments, the SM 132 can command the traversalcoprocessor 138 to perform different kinds of ray-primitive intersectiontests and report different results depending on the operations comingfrom an application (or an software stack the application is running on)and relayed by the SM to the TTU. For example, the SM 132 can commandthe traversal coprocessor 138 to report the nearest visible primitiverevealed by the intersection test, or to report all primitives the rayintersects irrespective of whether they are the nearest visibleprimitive. The SM 132 can use these different results for differentkinds of visualization. Once the traversal coprocessor 138 is doneprocessing the leaf nodes, there may be other branch nodes (pushedearlier onto the ray's stack) to test.

Multiple Intersections

In more detail, as shown in FIG. 3C, any given ray may intersectmultiple primitives within a bounding volume. Whether the rayintersection within a given primitive matters for visualization dependson the properties and position of that primitive as well as thevisualization procedures the SM 132 is performing. For example,primitives can be opaque, transparent or partially transparent (i.e.,translucent). Opaque primitives will block a ray from passing throughthe primitive because the eye cannot see through the primitive's opaquesurface. Transparent primitives will allow the ray to pass through(because the eye can see through the transparent primitive) but thesituation may be more complex. For example, transparent primitives mayhave specular properties that cause some portion of the ray to reflect(think of reflection from a window pane) and the rest of the ray to passthrough. Other transparent primitives are used to provide a surface ontowhich a texture is mapped. For example, each individual leaf of a treemay be modeled by a transparent primitive onto which an image of theleaf is texture mapped.

FIGS. 5A-5C illustrate some of these scenarios using an example of threetriangles assumed to be in the same bounding volume and each intersectedby a ray. FIG. 5A illustrates a ray directed towards these threetriangles, with the first triangle the ray encounters relative to theviewpoint being opaque. Because the “front” (from the standpoint of thedirection of the ray from the eye) intersected triangle is opaque, thattriangle will block the ray so the ray will not reach the othertriangles even through it spatially intersects them. In this example,the triangles “behind” the opaque triangle from the viewpoint can beignored (culled) after the intersection of the opaque triangle isidentified because the “front”, opaque triangle hides the othertriangles from the user's view along the ray. Culling is indicated bydotted lines in FIGS. 5A-5C. In this case, the traversal coprocessor 138may only need to report the identification of the first, opaque triangleto the SM 132.

FIG. 5B illustrates a ray directed towards the same three triangles butnow the nearest visible triangle is partially transparent rather thanopaque. Because the nearest visible intersected triangle is at leastpartially transparent, the ray may pass through it to hit the opaquetriangle behind it. In this case, the opaque triangle will be visiblethrough the partially transparent triangle but will block the user'sview of the third triangle along the ray. Here, the traversalcoprocessor 138 may report the identification of both front triangles tothe SM 132 but not report the third, culled triangle even though the rayspatially intersects that third triangle. Order of discovery may matterhere. In the case of an alpha and opaque triangle, if the opaque wasfound first, the traversal coprocessor 138 returns the opaque triangleto the SM 132 with traversal state that will resume testing at the alphatriangle. While there is an implication here that the alpha meanstransparent, it really means “return me to the SM 132 and let the SMdetermine how to handle it.” For example, an alpha triangle might betrimmed according to a texture or function so that portions of thetriangle are cut away (i.e., absent, not transparent). The traversalcoprocessor 138 does not know how the SM 132 will handle the alphatriangles (i.e., it does not handle transparent triangles differentlyfrom trimmed triangles). Thus, alpha triangles may or may not block ortint the light arriving from points beyond them along the ray, and inexample embodiments, they require SM 132 intervention tohandle/determine those things.

FIG. 5C illustrates a scenario in which the first two triangles the rayencounters are partially transparent. Because the first and secondintersected triangles are at least partially transparent, the ray willpass through the first and second triangles to impinge upon thealso-intersecting third opaque triangle. Because third intersectedtriangle is opaque, it will block the ray, and the ray will not impingeupon any other triangles behind the third triangle even though they maybe spatially intersected by it. In this case, the traversal coprocessor138 may report all three triangles to the SM 132 but need not report anyfurther triangles behind the opaque triangle because the opaque triangleblocks the ray from reaching those additional triangles.

In some modes, however, the SM 132 may need to know the identities ofall triangles the ray intersects irrespective of whether they are opaqueor transparent. In those modes, the traversal coprocessor 138 can simplyperform the intersection test and return the identities of all trianglesthe ray spatially intersects (in such modes, the traversal coprocessorwill return the same intersection results for all three scenarios shownin FIGS. 5A-5C) and allow the SM 132 to sort it out—or in some casescommand the traversal coprocessor 138 to do more tests on these sametriangles.

As will be discussed in more detail below, when a ray intersects anopaque triangle, the traversal coprocessor 138 can in certain operationsbe programmed to reduce the length of the ray being tested to thelocation of the opaque triangle intersection so it will not report anytriangles “behind” the intersected triangle. When a partiallytransparent triangle is determined to be intersected by a ray, thetraversal coprocessor 138 will return a more complete list of trianglesthe ray impinges upon for purposes of visualization, and the requestingSM 132 may perform further processing to determine whether, based forexample any texture or other properties of the triangle, the ray will beblocked, passed or partially passed and partially reflected. In exampleembodiments, the traversal coprocessor 138 does not have access totexture properties of triangles and so does not attempt to determinevisualization with respect to those properties.

Textures or Other Surface Modifications

For example, FIGS. 6A and 6B show a transparent triangle 610 with atexture 615 of a leaf applied to the triangle. One could think of atriangle made of Plexiglas with a decal of a leaf applied to it. Asshown in FIG. 6A, the ray 620 intersects the transparent triangle 610 ata point that is outside the applied texture 615. Because the ray 620intersects the triangle outside the applied texture 615, the texturewill not block the ray 620 and the ray will pass through the transparenttriangle 610 without obstruction. This is like being able to see throughthe parts of the Plexiglas triangle that are not covered by the leafdecal. Note that in one example embodiment, the SM 132 makes thevisibility determination since the traversal coprocessor 138 does notnecessarily have access to information concerning the leaf decal. Thetraversal coprocessor 138 helps the SM 132 by returning to the SM theidentification of the triangle that the ray intersects along withinformation concerning the properties of that triangle.

In FIG. 6B, the ray 630 intersects the transparent triangle where thetexture 615 is applied. SM 132 will determine whether subsequenttraversal by the traversal coprocessor 138 is necessary or not based onwhether the texture 615 will block the ray 630 or allow the ray 630 topass through. If the ray 630 is blocked by the texture 615, othertriangles behind the transparent triangle 610, which may have otherwisebeen intersected by the ray 630, will be obstructed by the texture andnot contribute to visualization along the ray. In the examplenon-limiting embodiments herein, the traversal coprocessor 138 does nothave access to texture information and so it does not attempt toaccelerate this determination. Traversal coprocessor 138 may for examplereturn to the requesting SM 132 all intersections between the ray andthe various triangles within the object, and the SM may then use thegraphics primitive engine 134 to make further ray tracing visualizationdeterminations. In other example embodiments, traversal coprocessor 138could accelerate some or all of these tests by interacting with thetexture mapping unit and other portions of the 3D graphics pipelinewithin graphics primitive engine 134 to make the necessary visualizationdeterminations.

Coordinate Transforms

FIGS. 2A-3C involve only a single object, namely a teapot. Just as theroom you are in right now contains multiple objects, most 3D scenescontain many objects. For example, a 3D scene containing a teapot willlikely also contain a cup, a saucer, a milk pitcher, a spoon, a sugarbowl, etc. all sitting on a table. In 3D graphics, each of these objectsis typically modelled independently. The graphics system 100 then usescommands from the processor 120 to put all the models together indesired positions, orientations and sizes into the common scene forpurposes of visualization (just as you will set and arrange the tablefor serving tea). What this means is that the SM 132 may commandtraversal processor 138 to analyze the same ray with respect to multipleobjects in the scene. However, the fact that each of these objects willbe transformed in position, orientation and size when placed into thecommon scene is taken into account and accelerated by the traversalcoprocessor 138. In non-limiting example embodiments, the transform fromworld-to-object space is stored in the world space BVH along with aworld-space bounding box. The traversal coprocessor 138 accelerates thetransform process by transforming the ray from world (scene) space intoobject space for purposes of performing the tests shown in FIG. 4. Inparticular, since the transformation of the geometry from object spaceinto world (scene) space is computationally intensive, thattransformation is left to the graphics pipeline graphics primitiveengine 134 and/or raster engine 136 to perform as part of rasterization.The traversal coprocessor 138 instead transforms a given ray from worldspace to the coordinate system of each object defined by an accelerationdata structure and performs its tests in object space.

FIGS. 7A and 7B illustrates how the traversal coprocessor 138 transformsthe same ray into three different object spaces. FIG. 7A shows threeobjects on a table: a cup, a teapot and a pitcher. These three objectsand a table comprise a scene, which exists in world space. A ray thatalso is defined in world space emanates from the viewpoint andintersects each of the three objects.

FIG. 7B shows each of the three objects as defined in object spaces.Each of these three objects is defined by a respective model that existsin a respective object space. The traversal coprocessor 138 in examplenon-limiting embodiments transforms the ray into the object space ofeach object before performing the intersection tests for that object.This “instance transform” saves the computational effort of transformingthe geometry of each object and the associated volumetric subdivisionsof the acceleration data structure from object space to world space forpurposes of the traversal coprocessor 138 performing intersection tests.

The requesting SM 132 keeps track of which objects are in front of whichother objects with respect to each individual ray and resolvesvisibility in cases where one object hides another object, casts ashadow on another object, and/or reflects light toward another object.The requesting SM 132 can use the traversal processor 138 to accelerateeach of these tests.

Example Tree BVH Acceleration Data Structure

FIGS. 8A and 8B show a recursively-subdivided bounding volume of a 3Dscene (FIG. 8A) and a corresponding tree data structure (FIG. 8B) thatmay be accessed by the traversal coprocessor 138 and used forhardware-accelerated operations performed by traversal coprocessor. Thedivision of the bounding volumes may be represented in a hierarchicaltree data structure with the large bounding volume shown in FIG. 2Brepresented by a parent node of the tree and the smaller boundingvolumes represented by children nodes of the tree that are contained bythe parent node. The smallest bounding volumes are represented as leafnodes in the tree and identify one or more geometric primitivescontained within these smallest bounding volumes.

The tree data structure may be stored in memory outside of the traversalcoprocessor 138 and retrieved based on queries the SMs 132 issue to thetraversal coprocessor 138. The tree data structure includes a pluralityof nodes arranged in a hierarchy. The root nodes N1 of the treestructure correspond to bounding volume N1 enclosing all of thetriangles O1-O8. The root node N1 may identify the vertices of thebounding volume N1 and children nodes of the root node.

In FIG. 8A, bounding volume N1 is subdivided into bounding volumes N2and N3. Children nodes N2 and N3 of the tree structure of FIG. 8Bcorrespond to and represent the bounding volumes N2 and N3 shown in FIG.8A. The children nodes N2 and N3 in the tree data structure identify thevertices of respective bounding volumes N2 and N3 in space. Each of thebounding volumes N2 and N3 is further subdivided in this particularexample. Bounding volume N2 is subdivided into contained boundingvolumes N4 and N5. Bounding volume N3 is subdivided into containedbounding volumes N6 and N7. Bounding volume N7 include two boundingvolumes N8 and N9. Bounding volume N8 includes the triangles O7 and O8,and bounding volume N9 includes leaf bounding volumes N10 and N11 as itschild bounding volumes. Leaf bounding volume N10 includes a primitiverange (e.g., triangle range) O10 and leaf bounding volume N11 includesan item range O9. Respective children nodes N4, N5, N6, N8, N10 and N11of the FIG. 8B tree structure correspond to and represent the FIG. 8Abounding volumes N4, N5, N6, N8, N10 and N11 in space.

The FIG. 8B tree is only three to six levels deep so that volumes N4,N5, N6, N8, N10 and N11 constitute “leaf nodes”—that is, nodes in thetree that have no child nodes. FIG. 8A shows that each of leaf nodebounding volumes N4, N5, N6, and N8, contains two triangles of thegeometry in the scene. For example, volumetric subdivision N4 containstriangles O1 & O2; volumetric subdivision N5 contains triangles O3 & O4;volumetric subdivision N6 contains trials O5 & O6; and volumetricsubdivision N8 contains triangles O7 & O8. The tree structure shown inFIG. 8B represents these leaf nodes N4, N5, N6, and N7 by associatingthem with the appropriate ones of triangles O1-O8 of the scene geometry.To access this scene geometry, the traversal coprocessor 138 traversesthe tree data structure of FIG. 8B down to the leaf nodes. In general,different parts of the tree can and will have different depths andcontain different numbers of triangles. Leaf nodes associated withvolumetric subdivisions that contain no geometry need not be explicitlyrepresented in the tree data structure (i.e., the tree is “trimmed”).

According to some embodiments, the subtree rooted at N7 may represent aset of bounding volumes or BVH that is defined in a different coordinatespace than the bounding volumes corresponding to nodes N1-N3. Whenbounding volume N7 is in a different coordinate space from its parentbounding volume N3, an instance node N7′ which provides the raytransformation necessary to traverse the subtree rooted at N7, mayconnect the rest of the tree to the subtree rooted at N7. Instance nodeN7′ connects the bounding volume or BVH corresponding to nodes N1-N3,with the bounding volumes or BVH corresponding to nodes N7 etc. bydefining the transformation from the coordinate space of N1-N3 (e.g.,world space) to the coordinate space of N7 etc. (e.g., object space).

The Internal Structure and Operation of Traversal Coprocessor 138

FIG. 9 shows an example simplified block diagram of traversalcoprocessor 138 including hardware configured to perform acceleratedtraversal operations as described above (a still more detailedimplementation of this traversal coprocessor 138 is described below).Because the traversal coprocessor 138 shown in FIG. 9 is adapted totraverse tree-based acceleration data structures such as shown in FIGS.8A, 8B, it may also be called a “tree traversal unit” or “TTU” 700 (the700 reference number is used to refer to the more detailed non-limitingimplementation of traversal coprocessor 138 shown in FIG. 1). Treetraversal operations may include, for example, determining whether a rayintersects bounding volumes and/or primitives of a tree data structure(e.g., a BVH tree), which tests may involve transforming the ray intoobject space.

The TTU 700 includes dedicated hardware to determine whether a rayintersects bounding volumes and dedicated hardware to determine whethera ray intersects primitives of the tree data structure. In someembodiments, the TTU 700 may perform a depth-first traversal of abounding volume hierarchy using a short stack traversal withintersection testing of supported leaf node primitives and mid-traversalreturn of alpha primitives and unsupported leaf node primitives (items).The intersection of primitives will be discussed with reference totriangles, but other geometric primitives may also be used.

In more detail, TTU 700 includes an intersection management block 722, aray management block 730 and a stack management block 740. Each of theseblocks (and all of the other blocks in FIG. 9) may constitute dedicatedhardware implemented by logic gates, registers, hardware-embedded lookuptables or other combinatorial logic, etc.

The ray management block 730 is responsible for managing informationabout and performing operations concerning a ray specified by an SM 132to the ray management block. The stack management block 740 works inconjunction with traversal logic 712 to manage information about andperform operations related to traversal of a BVH acceleration datastructure. Traversal logic 712 is directed by results of a ray-complettest block 710 that tests intersections between the ray indicated by theray management block 730 and volumetric subdivisions represented by theBVH, using instance transforms as needed. The ray-complet test block 710retrieves additional information concerning the BVH from memory 140 viaan L0 complet cache 752 that is part of the TTU 700. The results of theray-complet test block 710 informs the traversal logic 712 as to whetherfurther recursive traversals are needed. The stack management block 740maintains stacks to keep track of state information as the traversallogic 712 traverses from one level of the BVH to another, with the stackmanagement block pushing items onto the stack as the traversal logictraverses deeper into the BVH and popping items from the stack as thetraversal logic traverses upwards in the BVH. The stack management block740 is able to provide state information (e.g., intermediate or finalresults) to the requesting SM 132 at any time the SM requests.

The intersection management block 722 manages information about andperforms operations concerning intersections between rays andprimitives, using instance transforms as needed. The ray-primitive testblock 720 retrieves information concerning geometry from memory 140 onan as-needed basis via an L0 primitive cache 754 that is part of TTU700. The intersection management block 722 is informed by results ofintersection tests the ray-primitive test and transform block 720performs. Thus, the ray-primitive test and transform block 720 providesintersection results to the intersection management block 722, whichreports geometry hits and intersections to the requesting SM 132.

A Stack Management Unit 740 inspects the traversal state to determinewhat type of data needs to be retrieved and which data path (complet orprimitive) will consume it. The intersections for the bounding volumesare determined in the ray-complet test path of the TTU 700 including oneor more ray-complet test blocks 710 and one or more traversal logicblocks 712. A complet specifies root or interior nodes of a boundingvolume. Thus, a complet may define one or more bounding volumes for theray-complet test. The ray-complet test path of the TTU 700 identifieswhich bounding volumes are intersected by the ray. Bounding volumesintersected by the ray need to be further processed to determine if theprimitives associated with the intersected bounding volumes areintersected. The intersections for the primitives are determined in theray-primitive test path including one or more ray-primitive test andtransform blocks 720 and one or more intersection management blocks 722.

The TTU 700 receives queries from one or more SMs 132 to perform treetraversal operations. The query may request whether a ray intersectsbounding volumes and/or primitives in a BVH data structure. The querymay identify a ray (e.g., origin, direction, and length of the ray) anda BVH data structure and traversal state (e.g., short stack) whichincludes one or more entries referencing nodes in one or more BoundingVolume Hierarchies that the ray is to visit. The query may also includeinformation for how the ray is to handle specific types of intersectionsduring traversal. The ray information may be stored in the raymanagement block 730. The stored ray information (e.g., ray length) maybe updated based on the results of the ray-primitive test.

The TTU 700 may request the BVH data structure identified in the queryto be retrieved from memory outside of the TTU 700. Retrieved portionsof the BVH data structure may be cached in the level-zero (L0) cache 750within the TTU 700 so the information is available for othertime-coherent TTU operations, thereby reducing memory 140 accesses.Portions of the BVH data structure needed for the ray-complet test maybe stored in a L0 complet cache 752 and portions of the BVH datastructure needed for the ray-primitive test may be stored in an L0primitive cache 754.

After the complet information needed for a requested traversal step isavailable in the complet cache 752, the ray-complet test block 710determines bounding volumes intersected by the ray. In performing thistest, the ray may be transformed from the coordinate space of thebounding volume hierarchy to a coordinate space defined relative to acomplet. The ray is tested against the bounding boxes associated withthe child nodes of the complet. In the example non-limiting embodiment,the ray is not tested against the complet's own bounding box because (1)the TTU 700 previously tested the ray against a similar bounding boxwhen it tested the parent bounding box child that referenced thiscomplet, and (2) a purpose of the complet bounding box is to define alocal coordinate system within which the child bounding boxes can beexpressed in compressed form. If the ray intersects any of the childbounding boxes, the results are pushed to the traversal logic todetermine the order that the corresponding child pointers will be pushedonto the traversal stack (further testing will likely require thetraversal logic 712 to traverse down to the next level of the BVH).These steps are repeated recursively until intersected leaf nodes of theBVH are encountered

The ray-complet test block 710 may provide ray-complet intersections tothe traversal logic 612. Using the results of the ray-complet test, thetraversal logic 712 creates stack entries to be pushed to the stackmanagement block 740. The stack entries may indicate internal nodes(i.e., a node that includes one or more child nodes) that need to befurther tested for ray intersections by the ray-complet test block 710and/or triangles identified in an intersected leaf node that need to betested for ray intersections by the ray-primitive test and transformblock 720. The ray-complet test block 710 may repeat the traversal oninternal nodes identified in the stack to determine all leaf nodes inthe BVH that the ray intersects. The precise tests the ray-complet testblock 710 performs will in the example non-limiting embodiment bedetermined by mode bits, ray operations (see below) and culling of hits,and the TTU 700 may return intermediate as well as final results to theSM 132.

The intersected leaf nodes identify primitives that may or may not beintersected by the ray. One option is for the TTU 700 to provide e.g., arange of geometry identified in the intersected leaf nodes to the SM 132for further processing. For example, the SM 132 may itself determinewhether the identified primitives are intersected by the ray based onthe information the TTU 700 provides as a result of the TTU traversingthe BVH. To offload this processing from the SM 132 and therebyaccelerate it using the hardware of the TTU 700, the stack managementblock 740 may issue requests for the ray-primitive and transform block720 to perform a ray-primitive test for the primitives withinintersected leaf nodes the TTU's ray-complet test block 710 identified.In some embodiments, the SM 132 may issue a request for theray-primitive test to test a specific range of primitives and transformblock 720 irrespective of how that geometry range was identified.

After making sure the primitive data needed for a requestedray-primitive test is available in the primitive cache 754, theray-primitive and transform block 710 may determine primitives that areintersected by the ray using the ray information stored in the raymanagement block 730. The ray-primitive test block 720 provides theidentification of primitives determined to be intersected by the ray tothe intersection management block 722.

The intersection management block 722 can return the results of theray-primitive test to the SM 132. The results of the ray-primitive testmay include identifiers of intersected primitives, the distance ofintersections from the ray origin and other information concerningproperties of the intersected primitives. In some embodiments, theintersection management block 722 may modify an existing ray-primitivetest (e.g., by modifying the length of the ray) based on previousintersection results from the ray-primitive and transform block 710.

The intersection management block 722 may also keep track of differenttypes of primitives. For example, the different types of trianglesinclude opaque triangles that will block a ray when intersected andalpha triangles that may or may not block the ray when intersected ormay require additional handling by the SM. Whether a ray is blocked ornot by a transparent triangle may for example depend on texture(s)mapped onto the triangle, area of the triangle occupied by the texture(see FIGS. 6A and 6B) and the way the texture modifies the triangle. Forexample, transparency (e.g., stained glass) in some embodiments requiresthe SM 132 to keep track of transparent object hits so they can besorted and shaded in ray-parametric order, and typically don't actuallyblock the ray. Meanwhile, alpha “trimming” allows the shape of theprimitive to be trimmed based on the shape of a texture mapped onto theprimitive—for example, cutting a leaf shape out of a triangle. (Notethat in raster graphics, transparency is often called “alpha blending”and trimming is called “alpha test”). In other embodiments, the TTU 700can push transparent hits to queues in memory for later handling by theSM 132 and directly handle trimmed triangles by sending requests to thetexture unit. Each triangle may include a designator to indicate thetriangle type. The intersection management block 722 is configured tomaintain a result queue for tracking the different types of intersectedtriangles. For example, the result queue may store one or moreintersected opaque triangle identifiers in one queue and one or moretransparent triangle identifiers in another queue.

For opaque triangles, the ray intersection can be fully determined inthe TTU 700 because the area of the opaque triangle blocks the ray fromgoing past the surface of the triangle. For transparent triangles, rayintersections cannot in some embodiments be fully determined in the TTU700 because TTU 700 performs the intersection test based on the geometryof the triangle and may not have access to the texture of the triangleand/or area of the triangle occupied by the texture (in otherembodiments, the TTU may be provided with texture information by thetexture mapping block of the graphics pipeline). To fully determinewhether the triangle is intersected, information about transparenttriangles the ray-primitive and transform block 710 determines areintersected may be sent to the SM 132, for the SM to make the fulldetermination as to whether the triangle affects visibility along theray.

The SM 132 can resolve whether or not the ray intersects a textureassociated with the transparent triangle and/or whether the ray will beblocked by the texture. The SM 132 may in some cases send a modifiedquery to the TTU 700 (e.g., shortening the ray if the ray is blocked bythe texture) based on this determination.

In one embodiment, the TTU 700 may be configured to return all trianglesdetermined to intersect the ray to the SM 132 for further processing.Because returning every triangle intersection to the SM 132 for furtherprocessing is costly in terms of interface and thread synchronization,the TTU 700 may be configured to hide triangles which are intersectedbut are provably capable of being hidden without a functional impact onthe resulting scene. For example, because the TTU 700 is provided withtriangle type information (e.g., whether a triangle is opaque ortransparent), the TTU 700 may use the triangle type information todetermine intersected triangles that are occluded along the ray byanother intersecting opaque triangle and which thus need not be includedin the results because they will not affect the visibility along theray. As discussed above with reference to FIGS. 5A-5C, if the TTU 700knows that a triangle is occluded along the ray by an opaque triangle,the occluded triangle can be hidden from the results without impact onvisualization of the resulting scene.

The intersection management block 722 may include a result queue forstoring hits that associate a triangle ID and information about thepoint where the ray hit the triangle. When a ray is determined tointersect an opaque triangle, the identity of the triangle and thedistance of the intersection from the ray origin can be stored in theresult queue. If the ray is determined to intersect another opaquetriangle, the other intersected opaque triangle can be omitted from theresult if the distance of the intersection from the ray origin isgreater than the distance of the intersected opaque triangle alreadystored in the result queue. If the distance of the intersection from theray origin is less than the distance of the intersected opaque trianglealready stored in the result queue, the other intersected opaquetriangle can replace the opaque triangle stored in the result queue.After all of the triangles of a query have been tested, the opaquetriangle information stored in the result queue and the intersectioninformation may be sent to the SM 132.

In some embodiments, once an opaque triangle intersection is identified,the intersection management block 722 may shorten the ray stored in theray management block 730 so that bounding volumes (which may includetriangles) behind the intersected opaque triangle (along the ray) willnot be identified as intersecting the ray.

The intersection management block 722 may store information aboutintersected transparent triangles in a separate queue. The storedinformation about intersected transparent triangles may be sent to theSM 132 for the SM to resolve whether or not the ray intersects a textureassociated with the triangle and/or whether the texture blocks the ray.The SM may return the results of this determination to the TTU 700and/or modify the query (e.g., shorten the ray if the ray is blocked bythe texture) based on this determination.

Example Ray Tracing Shading Pipeline

FIG. 10A shows an exemplary ray tracing shading pipeline 900 that may beperformed by SM 132 and accelerated by TTU 700. The ray tracing shadingpipeline 900 starts by an SM 132 invoking ray generation 910 and issuinga corresponding ray tracing request to the TTU 700. The ray tracingrequest identifies a single ray cast into the scene and asks the TTU 700to search for intersections with an acceleration data structure the SM132 also specifies. The TTU 700 traverses (FIG. 10A block 920) theacceleration data structure to determine intersections or potentialintersections between the ray and the volumetric subdivisions andassociated triangles the acceleration data structure represents.Potential intersections can be identified by finding bounding volumes inthe acceleration data structure that are intersected by the ray.Descendants of non-intersected bounding volumes need not be examined.

For triangles within intersected bounding volumes, the TTU 700ray-primitive test block 720 performs an intersection 930 process todetermine whether the ray intersects the primitives. The TTU 700 returnsintersection information to the SM 132, which may perform an “any hit”shading operation 940 in response to the intersection determination. Forexample, the SM 132 may perform (or have other hardware perform) atexture lookup for an intersected primitive and decide based on theappropriate texel's value how to shade a pixel visualizing the ray. TheSM 132 keeps track of such results since the TTU 700 may return multipleintersections with different geometry in the scene in arbitrary order.

Alternatively, primitives that the TTU 700 determines are intersectedmay be further processed to determine 950 whether they should be shadedas a miss 960 or as a closest hit 970. The SM 132 can for exampleinstruct the TTU 700 to report a closest hit in the specified geometry,or it may instruct the TTU to report all hits in the specified geometry.For example, it may be up to the SM 132 to implement a “miss” shadingoperation for a primitive the TTU 700 determines is intersected based onimplemented environment lookups (e.g., approximating the appearance of areflective surface by means of a precomputed texture image) such asshown in FIGS. 6A & 6B. The SM 132 may perform a closest hit shadingoperation to determine the closest intersected primitive based onmaterial evaluations and texture lookups in response to closest hitreports the TTU 700 provided for particular object geometry.

The FIG. 10B more detailed diagram of a ray-tracing pipeline flowchartshows the data flow and interaction between components for arepresentative use case: tracing rays against a scene containinggeometric primitives, with instance transformations handled in hardware.In one example non-limiting embodiment, the ray-tracing pipeline of FIG.10B is essentially software-defined (which in example embodiments meansit is determined by the SMs 132) but makes extensive use of hardwareacceleration by TTU 700. Key components include the SM 132 (and the restof the compute pipeline), the TTU 700 (which serves as a coprocessor toSM), and the L1 cache and downstream memory system, from which the TTUfetches BVH and triangle data.

The pipeline shown in FIG. 10B shows that bounding volume hierarchycreation 1002 can be performed ahead of time by a development system. Italso shows that ray creation and distribution 1004 are performed orcontrolled by the SM 132 or other software in the example embodiment, asis shading (which can include lighting and texturing). The examplepipeline includes a “top level” BVH tree traversal 1006, raytransformation 1014, “bottom level” BVH tree traversal 1018, and aray/triangle (or other primitive) intersection 1026 that are eachperformed by the TTU 700. These do not have to be performed in the ordershown, as handshaking between the TTU 700 and the SM 132 determines whatthe TTU 700 does and in what order.

The SM 132 presents one or more rays to the TTU 700 at a time. Each raythe SM 132 presents to the TTU 700 for traversal may include the ray'sgeometric parameters, traversal state, and the ray's ray flags, modeflags and ray operations information. In an example embodiment, a rayoperation (RayOp) provides or comprises an auxiliary arithmetic and/orlogical test to suppress, override, and/or allow storage of anintersection. The traversal stack may also be used by the SM 132 tocommunicate certain state information to the TTU 700 for use in thetraversal. A new ray query may be started with an explicit traversalstack. For some queries, however, a small number of stack initializersmay be provided for beginning the new query of a given type, such as,for example: traversal starting from a complet; intersection of a raywith a range of triangles; intersection of a ray with a range oftriangles, followed by traversal starting from a complet; vertex fetchfrom a triangle buffer for a given triangle, etc. In some embodiments,using stack initializers instead of explicit stack initializationimproves performance because stack initializers require fewer streamingprocessor registers and reduce the number of parameters that need to betransmitted from the streaming processor to the TTU.

In the example embodiment, a set of mode flags the SM 132 presents witheach query (e.g., ray) may at least partly control how the TTU 700 willprocess the query when the query intersects the bounding volume of aspecific type or intersects a primitive of a specific primitive type.The mode flags the SM 132 provides to the TTU 700 enable the ability bythe SM and/or the application to e.g., through a RayOp, specify anauxiliary arithmetic or logical test to suppress, override, or allowstorage of an intersection. The mode flags may for example enabletraversal behavior to be changed in accordance with such aspects as, forexample, a depth (or distance) associated with each bounding volumeand/or primitive, size of a bounding volume or primitive in relation toa distance from the origin or the ray, particular instances of anobject, etc. This capability can be used by applications to dynamicallyand/or selectively enable/disable sets of objects for intersectiontesting versus specific sets or groups of queries, for example, to allowfor different versions of models to be used when application statechanges (for example, when doors open or close) or to provide differentversions of a model which are selected as a function of the length ofthe ray to realize a form of geometric level of detail, or to allowspecific sets of objects from certain classes of rays to make somelayers visible or invisible in specific views.

In addition to the set of mode flags which may be specified separatelyfor the ray-complet intersection and for ray-primitive intersections,the ray data structure may specify other RayOp test related parameters,such as ray flags, ray parameters and a RayOp test. The ray flags can beused by the TTU 700 to control various aspects of traversal behavior,back-face culling, and handling of the various child node types, subjectto a pass/fail status of an optional RayOp test. RayOp tests addflexibility to the capabilities of the TTU 700, at the expense of somecomplexity. The TTU 700 reserves a “ray slot” for each active ray it isprocessing, and may store the ray flags, mode flags and/or the RayOpinformation in the corresponding ray slot buffer within the TTU duringtraversal.

In the example shown in FIG. 10B, the TTU 700 performs a top level treetraversal 1006 and a bottom level tree traversal 1018. In the exampleembodiment, the two level traversal of the BVH enables fast ray tracingresponses to dynamic scene changes.

Ray transformation 1014 provides the appropriate transition from the toplevel tree traversal 1006 to the bottom level tree traversal 1018 bytransforming the ray, which may be used in the top level traversal in afirst coordinate space (e.g., world space), to a different coordinatespace (e.g., object space) of the BVH of the bottom level traversal. Anexample BVH traversal technique using a two level traversal is describedin previous literature, see, e.g., Woop, “A Ray Tracing HardwareArchitecture for Dynamic Scenes”, Universitat des Saarlandes, 2004, butembodiments are not limited thereto.

In some embodiments, the top level traversal (in world space) is made ina BVH that may be dynamically recalculated (e.g., by SM 132) in responseto changes in the scene, and the bottom level traversal is made in a BVHof bounding volumes that remain static or substantially static even whenchanges in the scene occur. The bounding volumes in the BVH used for thebottom level tree traversal 1018 (in object space) may encompass moredetailed information regarding the scene geometry than the respectivebounding volumes used in the top level tree traversal 1006, therebyavoiding or at least reducing the modification of the bottom leveltraversal BVH in response to scene changes. This helps to speed up raytracing of dynamic scenes.

Example Top Level Tree Traversal

The top level tree traversal 1006 by TTU 700 receives complets from theL1 cache 1012, and provides an instance to the ray transformation 1014for transformation or a miss/end output 1013 to the SM 132 for closesthit shader 1015 processing by the SM (this block can also operaterecursively based on non-leaf nodes/no hit conditions). In the top leveltree traversal 1006, a next complet fetch step 1008 fetches the nextcomplet to be tested for ray intersection in step 1010 from the memoryand/or cache hierarchy and ray-bounding volume intersection testing isdone on the bounding volumes in the fetched complet.

As described above, an instance node connects one BVH to another BVHwhich is in a different coordinate system. When a child of theintersected bounding volume is an instance node, the ray transformation1014 is able to retrieve an appropriate transform matrix from the L1cache 1016. The TTU 700, using the appropriate transform matrix,transforms the ray to the coordinate system of the child BVH. U.S.patent application Ser. No. 14/697,480, which is already incorporated byreference, describes transformation nodes that connect a first set ofnodes in a tree to a second set of nodes where the first and second setsof nodes are in different coordinate systems. The instance nodes inexample embodiments may be similar to the transformation nodes in U.S.application Ser. No. 14/697,480. In an alternative, non-instancing modeof TTU 700 shown in FIG. 10C, the TTU does not execute a “bottom” leveltree traversal 1018 and noninstanced tree BVH traversals are performedby blocks 1008, 1010 e.g., using only one stack. The TTU 700 can switchbetween the FIG. 10B instanced operations and the FIG. 10C non-instancedoperations based on what it reads from the BVH and/or query type. Forexample, a specific query type may restrict the TTU to use just thenon-instanced operations. In such a query, any intersected instancenodes would be returned to the SM.

In some non-limiting embodiments, ray-bounding volume intersectiontesting in step 1010 is performed on each bounding volume in the fetchedcomplet before the next complet is fetched. Other embodiments may useother techniques, such as, for example, traversing the top leveltraversal BVH in a depth-first manner. U.S. Pat. No. 9,582,607, alreadyincorporated by reference, describes one or more complet structures andcontents that may be used in example embodiments. U.S. Pat. No.9,582,607 also describes an example traversal of complets.

When a bounding volume is determined to be intersected by the ray, thechild bounding volumes (or references to them) of the intersectedbounding volume are kept track of for subsequent testing forintersection with the ray and for traversal. In example embodiments, oneor more stack data structures is used for keeping track of childbounding volumes to be subsequently tested for intersection with theray. In some example embodiments, a traversal stack of a small size maybe used to keep track of complets to be traversed by operation of thetop level tree traversal 1006, and primitives to be tested forintersection, and a larger local stack data structure can be used tokeep track of the traversal state in the bottom level tree traversal1018.

Example Bottom Level Tree Traversal

In the bottom level tree traversal 1018, a next complet fetch step 1022fetches the next complet to be tested for ray intersection in step 1024from the memory and/or cache hierarchy 1020 and ray-bounding volumeintersection testing is done on the bounding volumes in the fetchedcomplet. The bottom level tree traversal, as noted above, may includecomplets with bounding volumes in a different coordinate system than thebounding volumes traversed in the upper level tree traversal. The bottomlevel tree traversal also receives complets from the L1 cache and canoperate recursively or iteratively within itself based onnon-leaf/no-hit conditions and also with the top level tree traversal1006 based on miss/end detection. Intersections of the ray with thebounding volumes in the lower level BVH may be determined with the raytransformed to the coordinate system of the lower level completretrieved. The leaf bounding volumes found to be intersected by the rayin the lower level tree traversal are then provided to the ray/triangleintersection 1026.

The leaf outputs of the bottom level tree traversal 1018 are provided tothe ray/triangle intersection 1026 (which has L0 cache access as well asability to retrieve triangles via the L1 cache 1028). The L0 complet andtriangle caches may be small read-only caches internal to the TTU 700.The ray/triangle intersection 1026 may also receive leaf outputs fromthe top level tree traversal 1006 when certain leaf nodes are reachedwithout traversing an instanced BVH.

After all the primitives in the primitive range have been processed, theIntersection Management Unit inspects the state of the result Queue andcrafts packets to send to the Stack Management Unit and/or RayManagement Unit to update the ray's attributes and traversal state, setup the ray's next traversal step, and/or return the ray to the SM 132(if necessary). If the result queue contains opaque or alphaintersections found during the processing of the primitive range thenthe Intersection Management Unit signals the parametric length (t) ofthe nearest opaque intersection in the result queue to the raymanagement unit to record as the ray's tmax to shorten the ray. Toupdate the traversal state to set up the ray's next traversal step theIntersection Management Unit signals to the Stack Management Unitwhether an opaque intersection from the primitive range is present inthe resultQueue, whether one or more alpha intersections are present inthe result queue, whether the resultQueue is full, whether additionalalpha intersections were found in the primitive range that have not beenreturned to the SM and which are not present in the resultQueue, and theindex of the next alpha primitive in the primitive range for the ray totest after the SM consumes the contents of the resultQueue (the index ofthe next primitive in the range after the alpha primitive with thehighest memory-order from the current primitive range in the resultqueue).

When the Stack Management Unit 740 receives the packet from IntersectionManagement Unit 722, the Stack Management Unit 740 inspects the packetto determine the next action required to complete the traversal step andstart the next one. If the packet from Intersection Management Unit 722indicates an opaque intersection has been found in the primitive rangeand the ray mode bits indicate the ray is to finish traversal once anyintersection has been found the Stack Management Unit 740 returns theray and its results queue to the SM with traversal state indicating thattraversal is complete (a done flag set and/or an empty top level andbottom level stack). If the packet from Intersection Management Unit 722indicates that there opaque or alpha intersection in the result queueand that there are remaining alpha intersections in the primitive rangenot present in the result queue that were encountered by the ray duringthe processing of the primitive range that have not already beenreturned to the SM, the Stack Management Unit 740 returns the ray andthe result queue to the SM with traversal state modified to set the cullopaque bit to prevent further processing of opaque primitives in theprimitive range and the primitive range starting index advanced to thefirst alpha primitive after the highest alpha primitive intersectionfrom the primitive range returned to the SM in the ray's result queue.If the packet from Intersection Management Unit 722 indicates that noopaque or alpha intersections were found when the ray processed theprimitive range the Stack Management Unit 740 pops the top of stackentry (corresponding to the finished primitive range) off the activetraversal stack. If the packet from Stack Management Unit 740 indicatesor that either there are opaque intersections in the result queue andthe ray mode bits do not indicate that the ray is to finish traversalonce any intersection has been found and/or there are alphaintersections in the result queue, but there were no remaining alphaintersections found in the primitive range not present in the resultqueue that have not already been returned to the SM the Stack ManagementUnit 740 pops the top of stack entry (corresponding to the finishedprimitive range) off the active traversal stack and modifies thecontents of the result queue to indicate that all intersections presentin the result queue come from a primitive range whose processing wascompleted.

If the active stack is the bottom stack, and the bottom stack is emptythe Stack Management Unit 740 sets the active stack to the top stack. Ifthe top stack is the active stack, and the active stack is empty, thenthe Stack Management Unit 740 returns the ray and its result queue tothe SM with traversal state indicating that traversal is complete (adone flag set and/or an empty top level and bottom level stack). If theactive stack contains one or more stack entries, then the StackManagement Unit 740 inspects the top stack entry and starts the nexttraversal step. Testing of primitive and/or primitive ranges forintersections with a ray and returning results to the SM 132 aredescribed in co-pending U.S. patent application Ser. No. 16/101,066entitled “Method for Continued Bounding Volume Hierarchy Traversal onIntersection without Shader Intervention” and U.S. patent applicationSer. No. 16/101,196 entitled “Method for Handling Out-of-Order Opaqueand Alpha Ray/Primitive Intersections”, which are hereby incorporated byreference in their entireties.

While the above disclosure is framed in the specific context of computergraphics and visualization, ray tracing and the disclosed traversalcoprocessor could be used for a variety of applications beyond graphicsand visualization. Non-limiting examples include sound propagation forrealistic sound synthesis, simulation of sonar systems, design ofoptical elements and systems, particle transport simulation (e.g., formedical physics or experimental high-energy physics), general wavepropagation simulation, comparison to LIDAR data for purposes e.g., ofrobot or vehicle localization, and others. OptiX™ has already been usedfor some of these application areas in the past.

Watertight Ray Tracing

As discussed above with reference to FIGS. 3A-3C, after a boundingvolume containing geometric primitives (e.g., points, lines, triangles,quads, meshes, etc.) is determined to be intersected by a ray, furthertests may need to be performed to determine whether or not one or moreprimitives inside the intersected bounding volume are intersected by theray. For example, FIG. 8A described above illustrates bounding volumesN4-N6, N8, N10, N11 which may be represented by a leaf node N4-N6, N8,N10, N11 in a BVH. Each leaf node identifies a range of primitives(e.g., triangles O1 and O2 of leaf node N4) which are tested by the TTUfor intersection by a ray. However, in the example embodiment there isnothing to prevent leaf nodes from contacting or even overlapping oneanother. In some examples, adjoining primitives are connected at edgesand/or vertices to form a mesh representing the shape of the 3D object.For example, FIG. 3C illustrates a plurality of triangles connected atvertices and edges to form a mesh representing a portion of a teapot.

The traversal coprocessor 138 is configured to determine which trianglesare intersected by a ray and return intersection information to otherblocks of the graphics processing system (e.g., a streaming processor132) so that a scene can be generated based on identified intersections.The intersection determination may be performed in the ray-coordinatespace (e.g., by transforming the primitives and/or triangles into theray-coordinate space). In certain situations, the ray intersection testmay miss a triangle intersection due to, for example, complexity of thescene and/or precision limitations of the processing system. Missing atriangle intersection in a mesh of triangles providing a continuoussurface may result in a “crack”, void or other artifact in the generatedscene because a missed intersection does not for example provide thegraphics processor with information for it to apply the textureassociated with the missed triangle.

Similar situations occur when a child is putting together a puzzle butduring the process loses a piece of the puzzle. Once the pieces of thepuzzle are put together, the completed puzzle surface will have a voiddue to the missing piece. In this example, it is expected that if thenumber of puzzle pieces is increased and the size of the puzzle piecesis decreased, the child is likely to lose a larger number of puzzlepieces resulting in additional voids in the completed puzzle. Similarlyin graphics processing, increasing the scene complexity by includingadditional triangles and reducing the sizes of the triangles willincrease the likelihood that “cracks” will result in the generatedscene.

In hardware based ray tracing, triangle intersections may be missed dueto precision limitations of the computation hardware. Errors due toprecision of numerical computations may be particularly evident whenarithmetic operations involve very large and/or very small values. Thesesituations may arise for example in large and complex scenes includingsmall triangles which may be far away from the camera. Similarly,calculations involving thin and/or long triangles forming small or thinobjects, such as spaghetti, wires or hair, may present numericallychallenging computations. In a specific example, triangles having smallperimeters compared to the magnitude of the triangle coordinates, orneedle shaped triangles may cause numerical errors and missedintersections. For example, the math processor used to computeintersections may end up rounding or otherwise approximating very largeor very small numerical values used to represent geometry locations,causing errors in the resulting images that are readily visible anddetract from the photorealism of the scene.

Accordingly, hardware implementations of a ray-triangle intersectiontest may cause numerical inconsistencies and miss an intersection.Missing an intersection for a connected mesh of certain triangles (e.g.,opaque triangles) creates visible “cracks” in the mesh. These cracks canbe more prevalent at or near edges and/or vertices shared by thetriangles. It is difficult to accurately determine intersections at ornear edges and/or vertices because single-precision (32 bit)floating-point representation, which is commonly used in graphicsprocessing, may not provide the precision needed at these locations.Increasing the precision to for example double-precision floating-pointrepresentation increases processing complexity and still does notresolve all issues. For example, the precision needed at or near edgesand/or vertices using floating-point representation may be lost due torounding involved in addition, subtraction, and/or multiplication ofsmall values.

Exemplary non-limiting embodiments of this disclosure provide a TTUincluding hardware circuitry configured to properly handle numericallychallenging computations at or near edges and/or vertices of primitives.Proper handling of these computations provides for watertight rayintersection results at and near both edges and vertices of adjoiningprimitives. In a specific example, the TTU includes a fused floatingpoint operation unit, with an expanded exponent range (e.g., 10 bit),performing floating-point operations (e.g., single-precisionfloating-point operations). The fused floating point operation unitallows for multiple floating-point operations (e.g., two multiplicationsand one subtraction) to be combined into a single fused floating pointoperation. See e.g., Quinnell et al, Floating-Point Fused Multiply-AddArchitectures, Conference Record of the Forty-First Asilomar Conferenceon Signals, Systems and Computers (2007). The fused floating pointoperation units reduce space consumption, latency and/or number ofrounding operations for arithmetic operations. As will be discussed indetail below, TTU hardware circuitry including the fused floating pointoperation units with the expanded exponent range ensures that a ray doesnot miss a pair of triangles that share a common edge by passing betweenthem “through” the shared edge or vertex.

Single Hit Ray Tracing

In some cases a ray may intersect at or very close to an edge shared byadjoining triangles or a vertex shared by two or more other triangles.In these cases, especially with the occurrence of numeric computationerrors as discussed above, a conventional ray-triangle intersection testmight determine that the ray intersects each of the multiple trianglessharing an edge or a vertex. If the streaming processor (SM) 132 is toldthat each triangle sharing an edge or a vertex is intersected, furtherprocessing by the SM 132 based on multiple intersections at onelocation, instead of a single intersection, may generate inaccurateimages of the scene. However, a ray passing through a surface at an edgeor a vertex (special case) should not “look different” to theapplication issuing the query, compared to the ray passing neatlythrough a middle of a triangle (common case). A “single hit” may beprovided in a simple case of a ray passing from one side of awell-behaving surface to another.

Consider an example of rendering a glass object. One way to assist withrendering the glass object is to count the number of semi-transparentsurfaces intersected by a ray and aggregate partial opacity assigned tothe surfaces along the ray. When rendering an image of the glass objectusing rasterization, the triangles of the glass object may be drawn ontop of the already drawn scene with the aggregated opacity applied tothe triangles of the glass object. Suppose that the processing system isrendering a flat or one sided glass surface assigned a partial opacity.If the ray intersects an edge shared by two triangles, the TTU 138 maydetermine that both triangles are intersected by the ray on the edge. Inthis case, the processing system will aggregate the partial opacityassigned to each triangle and generate an image with an opacity that isdoubled compared to the appropriate opacity value for the surface.Accordingly, the surface will look darker than the surrounding surfacein the rendered image.

In another example, the processing system may need to track whether theray is currently inside or outside of an object at a given location in ascene. If there is a guarantee that when the ray enters an object(passes through the surface) the ray tracer reports an intersection andwhen the ray exits an object (passes through the next surface) the raytracer reports another intersection, then it is possible to just countthe number of encountered intersections to track whether the ray iscurrently inside or outside of an object. If zero intersections arereported then the ray is outside of the object, whereas if a singleintersection is reported then the ray is inside of the object, and iftwo intersections are reported then the ray is again outside of theobject. If the ray intersects an edge shared by two triangles and twohits are reported, the processing system may incorrectly interpret agiven location in a scene.

Exemplary non-limiting embodiments of this disclosure provide a TTUincluding hardware circuitry configured to properly determine the numberof intersections when a ray intersection is at or near an edge, a vertexor other spatial region shared by plural primitives. For example, theTTU is configured to guarantee that when a ray goes through a closedmesh, even if it passes through an edge between two triangles or througha vertex shared by multiple triangles, the TTU will still report onlyone intersection. Exemplary non-limiting embodiments of this disclosureprovide tie-breaking rules implemented in the TTU to determined whichtriangle or other primitive sharing an edge or vertex will be indicatedas being intersected by a ray.

It is noted that in certain situations it may be incorrect to report asingle hit whenever a ray passes through a vertex or an edge. Forexample, consider a ray grazing a surface at a point but which does notactually pass through it. In this case the system may be configured toreturn an even number of intersections, which would be a correct result.In cases where a ray hits a silhouette edge (i.e., both triangles are onthe same side of the edge from the ray's viewpoint), the system may beconfigured to report either zero or two intersections. Returning resultswith zero or two intersections would be correct for the silhouette edge,depending on which side of the ray the two triangles are. For vertexhits, it may be possible to construct more complicated cases where aclosed mesh yields an arbitrary number of hits when a ray goes through avertex. The true invariant is the odd/even number of hits that maydepend only on whether the ray moves from one side of a connectedsurface to the other side.

FIG. 11A illustrates a case where a ray goes exactly through an edge (inpost-shear coordinates) but does not enter a box formed of a pluralityof triangles. In this case, tie-breaking may never report just one hit,but will either report both triangles A and B as being hit, or neitherof them as being hit. This is the correct and desired behavior. Which ofthe two cases happens is inconsequential. From the application'sperspective the situation may look like the ray had passed just outsidethe box (miss both triangles) or just inside the box (hit bothtriangles). In these situations, the edge should not look like thespecial case of a returning a single hit. It should be noted that thesekind of cases can get handled correctly (e.g., automatically) if thecase of going through a surface is handled correctly.

Whether a single hit or multiple hits are returned may depend on thetype of query and/or type of objects (e.g., surface type and/orgeometry) being tested. In an exemplary embodiment, hardware circuitrymay be configured to always report a single triangle hit upon a rayintersecting a connected mesh of triangles at an edge or vertex. Thismay be true in cases where a ray moves from one side of a connectedsurface to another side. In other exemplary embodiment, hardwarecircuitry may be configured to report zero or multiple intersectionswhen a ray intersecting a connected mesh of triangles at an edge orvertex.

Example Watertight Ray Primitive Traversal Implementation

Exemplary non-limiting embodiments of this disclosure provide a TTUincluding hardware circuitry configured to properly determineintersections when a ray intersects at or near an edge or a vertexshared by a plurality of primitives. At least some of the non-limitingembodiments of this disclosure do not need to rely upon a fallback pathto double (or higher) precision arithmetic and/or exhibit a single-hitproperty through the use of tie-breaking rules when the edge equation iscalculated to be exactly zero.

FIG. 11B is a flowchart of an example non-limiting method fordetermining ray-primitives intersections. One or more operationsdiscussed with reference to FIG. 11B may be performed by a TTU 700disclosed in this application, but the example implementations are notso limited.

The method includes receiving a request for a nearest intersectionbetween a query data structure and a primitive range (step 1110). Therequest may be received from an SM 132 or may be the result ofray-complet test performed by the ray-complet test path of the TTU 700.The request may request a nearest intersection. In some embodiments, thequery data structure may be a ray given by its three-coordinate origin,three-coordinate direction, and minimum and maximum values (tmin, tmax)for the parametric interval (t-parameter) along the ray (e.g.,representing the segment of current interest along the ray). Theprimitive range for the request may be identified in one or more stackentries of a stack management block in the TTU 700. The stack entriesmay be made based on results of finding intersected leaf nodes of a BVHin the ray-complet test path of the TTU 700.

The primitive range is retrieved from memory (step 1112). The primitiverange may be retrieved from the TTU memory (e.g., triangle cache 754 ofL0 cache 750) or memory outside of the TTU 700. The primitive range may,for example, be provided in a contiguous group of cacheline-sizedblocks. Each cacheline-sized block may include a header identifying thetype of geometry expressed within the block and a primitive type of eachprimitive in the block. For example, the header may identify that theblock includes triangles and may indicate whether each triangle is analpha primitive or an opaque primitive. The header may include an alphabit for each primitive to designate whether the respective primitive isan alpha primitive or an opaque primitive.

The method includes transforming the ray and/or the primitives (step1114). The ray and/or primitives are transformed to simplify the 3Dintersection problem and decrease the floating point resources needed inthe TTU hardware to perform the intersection test. In one example, thetransformation may include translation, shear, and/or scaletransformations from world space to ray-coordinate space. In theray-coordinate space the ray may start at the origin and extend (e.g.,with unit length) along one coordinate axis. In some implementations,the TTU hardware applies an affine primitive transformation to the rayso that the primitive is a unit primitive with edge points at (1,0,0),(0,1,0) and (0,0,0).

Using the transformed ray and/or primitives, a determination is made asto which primitives are intersected by the ray (step 1116). Thetransformations applied to the ray and primitive simplify theintersection problem from 3D space to 2D space with simplified planarcoordinates (e.g., 2D ray-relative coordinates). In the 2D space, theintersection test becomes determining if the ray intersection is insideedges of the primitive (e.g., triangle edges).

For a triangle, the intersection determination can be computed usingthree 2D edge tests which indicate whether the ray passes on one side ofthe edge (represented with a positive value), an opposite side of theedge (represented by a negative value), or intersects an edge(represented by zero). The signs of the three 2D edge tests areinspected to determine if the ray intersects or misses the triangle. Inone non-limiting example, if all of the signs are positive or all of thesigns are negative then the triangle is intersected by the ray. If oneof the signs does not match the other two signs, then the ray is outsideof the triangle. If the result produces one or more zeros then theintersection may be on an edge or a vertex. In one example embodiment,if result of the 2D edge test includes a single zero then the TTUdetermines that the intersection may be on an edge; if the result of the2D edge test includes two or more zeros then the TTU determines that theintersection may be on a vertex. Because the edge or vertex may beshared by other triangles, tie breaking rules implemented, for example,in TTU logic, may be used to ensure that a single intersection isreturned. Other sign conventions can also be adopted to determineintersections.

Intersection results may be inaccurately determined at or near an edgeor vertex of a triangle because small results are often computed atthese locations and rounding in floating point arithmetic operations canproduce insufficient precision to make accurate spatial determinations.For example, computations for a ray intersection near an edge or vertexwill produce a small positive or negative value, which may get roundedto zero during the computations by the limited precision computationhardware. To address this issue, example non-limiting embodiments usefused floating point operation units configured to combine multiplefloating-point arithmetic operations to efficiently achieve highernumerical precision. The fused floating point operation units may beimplemented in hardware included in the TTU and in some exampleembodiments, in the Ray Triangle Test (RTT) block of the TTU (see e.g.,block 720 in FIG. 9).

Fused floating point operation units reduce latency and improve accuracydue to fewer rounding steps. Some exemplary non-limiting embodiments usefused floating point operation units with expanded exponent range toguarantee that there is no underflow or overflow in the floating pointexponents. The fused floating point operation unit allows for moreprecise ray-triangle results because the sign of the results is used todetermine if the triangle is hit or not and the fused floating pointoperation unit ensures that the sign of the results is correct eventhough the values may get rounded.

If the TTU determines an intersection, then it can also determine thecoordinates of the intersection. The intersection coordinates may beprovided for example by barycentric coordinates for further processing(e.g., computation of texture coordinates) by the SM 132 or in someother (e.g., future) implementations by hardware within the TTU.

Intersection information for primitives determined to be intersected bythe ray is returned to the SM 132 (step 1118). In one example, the TTU700 returns a closest hit primitive to the SM 132. In one exemplaryembodiment, the results returned to the SM 132 may include, for eachintersected primitive, a parametric length which specifies the pointalong the ray where the hit occurred and attributes of the hit such asthe instance ID, material ID, or which can be used by the SM to select aspecific material shader and a set of resource bindings, and primitiveIDs and (u,v) coordinates which can be used by the SM during shading toretrieve and interpolate attributes or sample textures.

The TTU 700 may return results to the SM 132 when a request completes ormid-traversal if the need should arise for SM intervention (for example,if the number of alpha hits found within a single triangle range exceedsthe storage capacity for alpha hits in the result queue). If all of theprimitives in the request are opaque, then the TTU 700 can return onlythe closest opaque primitive to the SM 132. However, if the primitivesinclude a mixture of opaque and alpha primitives, a plurality of alphaprimitives may be intersected by the ray. Each of the intersected alphaprimitives may be returned to the SM 132 for further processing (e.g.,to determine if there is a hit based on texture information associatedwith the alpha primitive). The SM 132 may use the results to build thescene, issue additional queries to the TTU 700, and/or modify previouslyissued queries to the TTU.

Example Non-Limiting Watertight Intersection Determination

FIG. 12 shows an example non-limiting process for determiningintersections between a ray and one or more triangles. While the stepsin FIG. 12 are described with reference to specific numerical operationsfor determining an intersection, the embodiments of this disclosure arenot limited to the disclosed numerical operations.

The TTU performs a ray/triangle intersection test to determine whether aray intersects a triangle and provides an intersection location if anintersection is determined. The ray R(t) with origin P and direction Dcan be defined as R(t)=P+tD and the triangle can be defined by its threevertices p0, p1, and p2.

To simplify the intersection problem, geometric translations are appliedto the ray and/or the triangle. First, a new coordinate space is defined1210 to simplify the calculations. In one example, the coordinate spaceis defined relative to the ray where the ray origin becomes thecoordinate space origin at (0,0,0), and the major axis of the raydirection vector (the coordinate with the largest absolute value)becomes the normalized Z-axis (0,0,1) of the coordinate space. The raymay be defined in ray-relative coordinates by simplified ray R′ withorigin P′=(0,0,0) and direction D′=(0,0,1).

A permutation transform may be computed as a function of the raydirection vector 1212, which includes computing the largest-magnitudecomponent of the ray direction vector (X, Y, or Z) and swapping thatcomponent with the Z-component. If the permuted Z-component is negative,the permuted X-axis and Y-axis components are swapped. The permutationtransform is applied to ray origin, ray direction, and/or trianglevertices 1214, and the ray origin is subtracted from all trianglevertices 1216. Subtracting the ray origin transforms the ray and thetriangles so that ray origin is at the 3D coordinate system origin.

The coefficients of the shear transform are computed 1218, which takethe x and y component of the ray direction vector to zero. The sheartransform is applied to the triangle vertices 1220. The pre-calculatedtransformation may be provided by:

$M = {\begin{pmatrix}1 & 0 & {{- D_{x}}/D_{z}} \\0 & 1 & {{- D_{y}}/D_{z}} \\0 & 0 & {1/D_{z}}\end{pmatrix}.}$

The transformed triangle vertices may be provided by:p0′=M·(p0−P),p1′=M·(p1−P),p2′=M·(p2−P).

In some embodiments, the transformation may be pre-determined by the TTUand applied to the triangle vertices by the Ray Triangle Test (RTT)block.

The 2D edge test is evaluated by computing the barycentric coordinates1222 of the sheared 2D triangle at (x=0, y=0). Barycentric coordinatescan be used to express the position of any point located on the trianglewith three scalars. The location of this point includes any positioninside the triangle, any position on any of the three edges of thetriangles, or any one of the three triangle's vertices themselves.

A vertex-winding order is determined 1224 by inspecting the signs of thebarycentric coordinates and applying a backface culling test. If thepoint at (x=0, y=0) is inside of all three edges and has the desiredfacing, the parametric length of the point of intersection is calculated1226. The parametric length of the intersection point may be calculatedby interpolation of the vertex z-components.

The barycentric coordinates can be provided by:U=D′·(p2′×p1′),V=D′·(p0′×p2′),W=D′·(p1′×p0′).

The barycentric coordinates can be further simplified due to unit rayintersection with direction D′=(0,0,1). The simplified barycentriccoordinates provide three 2D edge tests:U=p2_(x) ′·p1_(y) ′−p1_(x) ′·p2_(y)′,V=p0_(x) ′·p2_(y) ′−p2_(x) ′·p0_(y)′W=p1_(x) ′·p0_(y) ′−p0_(x) ′·p1_(y)′.

The signs of the three 2D edge tests may be inspected to determine ifthe ray intersects or misses the triangle. In one example, if all of thesigns are positive or all of the signs are negative, then the triangleis intersected by the ray. If one of the signs does not match the othertwo signs, then the intersection is outside of the triangle. If theresult produced one or more zeros, then the intersection may be on anedge or a vertex of the triangle. Because the edge or vertex may beshared by other triangles, tie breaking rules may be needed to ensurethat only a single intersection is returned.

Embodiments of this disclosure provide for computing a first part of theintersection test using enough precision and enough expanded exponentrange so that a guarantee can be made that there is no underflow oroverflow in the floating point exponents. Exemplary non-limitingembodiments of this disclosure provide for a Ray/Triangle intersectiontest realized via a single-precision custom floating-point datapath withfused math units and special handling for corner cases.

In example non-limiting embodiments, the shear coefficients (−Dx/Dz and−Dy/Dz) may be clamped to the [−1,+1] to eliminate pathological caseswhere rounding causes one or both shear coordinates to lie outside thenatural algebraic gamut of [−1,+1] which can cause vertex winding orderchanges that can cause missed triangles to be hit or hits to be missed.

In example non-limiting embodiments, the edge tests may operate onunnormalized barycentric coordinates instead of normalized barycentricsand may be computed using fused floating point operation units (e.g.,fused 2-component dot product units—fused DP2 units) with expanded10-bit exponent range to ensure that exponent underflow cannot cause theedge test to produce a denormalized or zero result. In some exampleembodiments, the edge test may operate on normalized barycentrics.

Using the DP2 unit may avoid loss of precision because instead ofperforming individual operations which may each include their ownprecision loss (e.g., due to rounding), the DP2 unit allows forexecuting of an entire expression (e.g., of the unnormalized barycentriccoordinates) in one fused floating point operation. The intermediateresults can be considered with full precision and the rounding wouldonly happen at the very end so that the sign will always be correct.

FIG. 13 shows a single-precision floating-point representation andexpanded exponent single-precision floating-point representation. Thesingle-precision floating-point includes a sign bit (1 bit), exponent (8bits), and significant precision (23 bits). The expanded exponentsingle-precision floating-point representation includes a sign bit (1bit), exponent (10 bits), and significant precision (23 bits). Thesingle-precision floating-point occupies 32 bits in memory and theexpanded exponent single-precision floating-point representationoccupies 34 bits in memory.

The expanded 10-bit exponent range expands the exponent in thesingle-precision floating-point representation by two bits to ensurethat the exponent of the DP2 result will never be too large or too smallto be representable in the expanded 10 bit exponent. The expandedexponent range thus prevents all overflows and underflows. Without theexpanded exponent range, underflows could occur when determiningintersections near an edge or a vertex because the intermediate or finalresult is smaller in magnitude (i.e., closer to zero) that the smallestvalue representable by the single-precision floating-pointrepresentation.

Previous techniques attempt to address underflow issues by usingdouble-precision floating point representation when a result includeszero. However, double-precision floating point representation requiresmore processing hardware. In addition, previous techniques were limitedby the CPU architecture used to perform the calculation. Typical CPUarchitectures execute the floating point operations individually (e.g.,they execute one multiply, followed by a second multiply and thensubtraction).

In example non-limiting embodiments, the edge-tests may treat Inf or NaNbarycentric coordinate values as misses.

In example non-limiting embodiments, the 34 b representation isconverted to 32 b unnormalized barycentrics by normalizing the threeexponents to the largest exponent used in subsequent computations andflushing underflows to sign-preserving zero. The determinant used tocompute the normalized barycentric coordinates can be computed with afused three-way-adder and an FRCP (a single-precision floating-pointapproximate reciprocal unit configured to compute 1/x, approximately)which, in some embodiments, may be identical to the FRCP in the SM.

A v0-relative z-coordinates (v1mv0.z, v2mv0.z) of vertices of thetriangle can be computed by adding the (−v0.z, −v0.z) to triangle vertexz coordinates (v1.z, v2.z) with an FADD (a single-precisionfloating-point addition unit configured to compute “a+b” and round theresult to the precision of fp32) which, in some embodiments, may beidentical to the FADD found in the SM.

A v0-relative z-component of the intersection point, z, can be computedby computing (v1mv0.z*u+v2mv0.z*v+v0.z) using a fused 2-componentdot-product accumulate (FDP2A). The parametric length, t, may becomputed by multiplying z by the reciprocal ray direction vector rcpDirZusing an FMUL (a single-precision floating-point multiply unitconfigured to compute “a*b” and round the result to the precision offp32) which, in some embodiments, may be identical to the FMUL found inthe SM. The parametric length, t, may be obtained by operation“t=z/dirZ”.

In example non-limiting embodiments, the edge tests may employtiebreaking rules to prevent a ray passing near an edge shared by twotriangles from reporting intersections with both triangles.

If the fused dot product of an edge test generates a zero, the inputs(a, b, c, d) of the dot-product (a*b+c*d) may be compared to potentiallyoverride the result. For example, an exact zero may be returned if(((a==−c) AND (b==d)) is true. This corresponds to the case where thetwo 2D vertices of an edge are identical. Otherwise, if ((a>−c) OR((a==−c) AND (d>b))) is true, a positive sign may be returned. In theremaining cases where ((a<−c) OR ((a==−c) AND (d<b))) is true, anegative sign may be returned. In some embodiments, logic (e.g., in acomparator) may be configured to receive the inputs and outputs of thedot-product and determine whether to override the result of the edgetest.

Example Ray Primitive Traversal with Single Hit Return

As discussed above, when a ray goes through a closed mesh the TTU 700can be configured to determine a single intersection even if the raypasses through an edge between two triangles or through a vertex sharedby multiple triangles. To ensure this property, exemplary non-limitingembodiments of this disclosure provide tie-breaking rules to return asingle intersection. The TTU 700 may include hardware circuitryconfigured to implement these rules.

In example non-limiting embodiments, high-level operations that RTT doesto determine whether a ray, or rather its infinite extension, intersectsa triangle include:

-   -   1. Determine a permutation that takes the largest-magnitude        component of ray direction vector to its z component. Apply this        permutation to all 3D vectors (ray origin, ray direction,        triangle vertices).    -   2. Subtract ray origin from all triangle vertices. This        transforms the ray and the triangle so that ray origin is at the        3D coordinate system origin.    -   3. Construct a shear transform that takes x and y components of        ray direction vector to zero, and apply this to the triangle        vertices. Now we look for an intersection between the        post-transform triangle, formed by the transformed vertices, and        a ray from (0, 0, 0) towards (0, 0, dz).    -   4. This is a 2D test, so we forget about z component,        effectively projecting everything on the x, y plane. We        conceptually form the 2D edge functions of the post-transform        triangle edges and evaluate those edge functions at the 2D        origin.    -   5. Based on the signs of the edge function evaluations at the        origin, we can determine if a triangle was hit or not.

These steps determine if an infinitely long ray with the same directionvector would intersect the triangle. The fact that the ray has finiteextents (at both ends) is handled by computing the intersection t valueand comparing it against the ray parameters and possibly the t value ofa previously found hit. This is similar to how z affects rasterization.

Steps 1-3 produce the exact same post-transform vertex as long as theray is the same and the world-space input vertex position is the same.Thus, a connected mesh in world space will transform into a connectedmesh in post-transform space, and no cracks can appear due to thesesteps. However, as discussed above, cracks could still be introducedinto the generated scene if intersections are incorrectly identified.

In example non-limiting embodiments, the 2D edge functions in step 4 mayinclude the following operations. For two post-transform trianglevertices (p0′x, p0′y) and (p1′x, p1′y), the edge function they define isof the form:Ax+By+C, where

A=something,

B=something, and

C=p1′x*p0′y−p0′x*p1′y.

In example non-limiting embodiments, components A and B may not matterbecause the edge function will be evaluated at the 2D origin. Thus, theconstant term C is the only value that may matter. The C value isdetermined for each pair of vertices (p0′x, p0′y) and (p1′x, p1′y);(p1′x, p1′y) and (p2′x, p2′y); and (p2′x, p2′y) and (p0′x, p0′y). Withthree edge functions, a hit is determined if the signs of all of themare the same when evaluated at the origin, or in other words, if C hasthe same sign for all three edge functions.

If C is not exactly zero for any of the edges, everything is fine.However, in some exemplary embodiments, the sign of C must be evaluatedexactly, with infinite precision, in order to be consistent when the raydoes not pass exactly through an edge or a vertex. If the sign of C isnot correct due to roundoff errors, problems will be present not only atthe edges and vertices, but near the edges and vertices. In some exampleembodiments, a fused DP2 is used for the calculation of the sign of C,and a result that would flush to zero when truncated to FP32 is replacedwith the smallest representable value of the correct sign.

If C is exactly zero, the geometry of the situation must be considered:In this case, the 2D edge (or its extension) passes exactly through theorigin. These kinds of situations can be disambiguated by perturbing thetriangle vertices infinitesimally, i.e., by nudging them slightly. Aslong as this is done in a consistent manner, the single-hit propertyfalls out.

In practice, finite epsilons are not added anywhere, but instead thelogic implementations see what would happen with an infinitesimallysmall perturbation. This is what the tie-breaking rules at the end ofFDP2_SGN operation do. The FDP2_SGN operation includes the combinationof a non-overflowing fused DP operation (using expanded exponent rangeas explained above) followed by the tie-breaking logic.

In an example non-limiting embodiment, the vertices are first nudgedalong one axis, and if this resolves the sign of C, we're done. If not,the vertices are nudged along another axis (we can imagine adding aneven smaller epsilon there), and in all but degenerate cases this willresolve the sign of C in a consistent fashion.

In a specific example, we first see what would happen if we nudged bothvertices towards the positive y direction. Denoting the infinitesimallysmall but positive epsilon by e, we have

$\begin{matrix}\left. {{{{\left. {{{{{C’} = {p\; 1}}’}x*\left( {p\; 0}’ \right.y} + e} \right) - {p\; 0}}’}x*\left( {p\; 1}’ \right.y} + e} \right) \\{{{{{{= {C + {p\; 1}}}’}x*e} - {p\; 0}}’}x*e}\end{matrix}$because C=0, we have just C′=(p1′x−p0′x)*e, and thussign(C′)=sign(p1′x−p0′x).

Thus, if (p1′x>p0′x) we output a positive result, and if (p1′x<p0′x) weoutput a negative result. In a specific implementation, because p0′x ispassed into FDP2_SGN negated as the third parameter, p0′x may be negatedat the test at the end of FDP2_SGN to recover the original p0′x value.

If nudging the vertices in y direction does not resolve the sign, theedge is then be exactly vertical, i.e., p0′x=p1′x. In addition,remembering that the edge passes exactly through the origin, we musthave p0′x=p1′x=0. In this case, in a specific implementation, thevertices can be nudged in negative x direction in order to resolve thedegeneracy. We have:

$\begin{matrix}{{{\left. {{{{\left. {{C"} = {{\left( {p\; 1}’ \right.x} - e}} \right)*p\; 0}’}y} - {\left( {p\; 0}’ \right.x} - e} \right)*p\; 1}’}y} \\\left. {{{= {{e*\left( {p\; 1}’ \right.y} - {p\; 0}}}’}y} \right)\end{matrix}$and sign (C″)=sign(p1′y−p0′y). Thus, if (p1′y>p0′y) we output a positiveresult, and if (p1′y<p0′y) we output a negative result.

The only remaining case is where p0′x=p1′x and p0′y=p1′y, i.e., the twovertices that form an edge are exactly equal. In this case C=0 no matterwhat we try. This is the only situation where FDP2_SGN returns a zero,and in this case, similarly to what rasterizer does with two identicalvertices, we never hit the triangle.

FIG. 14 is a flowchart of an example non-limiting ray-triangleintersection test providing a single hit return for a closed mesh. Theray-triangle intersection may be performed in the ray-coordinate spaceby applying translation and shear transformation before evaluating theedge functions. One or more operations discussed with reference to FIG.14 may be performed by a TTU 700 disclosed in this application, but isnot so limited. While the operations discussed with reference to in FIG.14 are described with reference to triangles and specific single hitrules, the operations described can be extended to other primitives andrules.

In step 1410, a triangle is received to test whether a ray intersects atriangle. In step 1412, the vertices of the triangle are transformed tosimplify the intersection problem into a 2D space. As discussed above,the vertices (and the ray) may be transformed so that the ray origin isat the 3D coordinate system origin. This step may include subtractingthe ray origin from all triangle vertices and applying a shear transformthat takes the x and y component of ray direction vector to zero.

In step 1414, the values for the 2D edge functions are determined. Inone example, the C component of Ax+By+C is determined for each pair ofvertices of the triangle. Components A and B may be not consideredbecause the edge function is tested at the 2D origin. As discussedabove, fused DP2 units may be used to ensure that the sign of the testis determined exactly. In step 1416, a determination is made whether anyof the edges function values are zero.

If the edge function values do not include any zeros (No in step 1416),then a determination may be made as to whether the edge function valuesare all positive or negative (step 1418). If the edge function valuesare all positive or if the edge function values are all negative (Yes instep 1418) then the ray intersects inside of the edges of the triangleand the intersection for the triangle can be identified (step 1420). Theintersected triangle information may be added to a results queue ortransmitted to an SM for further processing. The intersectioninformation may include t-value representing a parametric length alongthe ray (point along the ray where the intersection occurred) andbarycentric coordinates of the intersection on the triangle. In step1420, if intersection t-value is not within the t range specified forthe ray, an intersection may not be identified.

If the edge function values are not all positive or if the edge functionvalues are not all negative (No in step 1418) then the ray does notintersect the triangle and the ray-triangle test is ended. At thispoint, the next triangle in a triangle range being tested may be testedfor an intersection with the ray.

If the edge function values include a zero (Yes in step 1416), then theray intersects the triangle on an edge or a vertex and a tie-breakingrule is applied to determine whether the ray will be returned as a hitor not. The tie-breaking rule ensures that a single triangle is returnedwhen the ray intersects a shared edge or vertex. The tie braking rulesmay be implemented with hardware (see e.g., comparator 1550 in FIG. 15configured to implement the tie braking rules by comparing the values oftransformed vertices). In other examples, tie braking rules may beimplemented by hardware circuitry configured to perform steps 1422-1434.

As shown in FIG. 14, if the edge function values include a zero (Yes instep 1416), then the triangle vertices are conceptually moved along afirst axis of the 2D space (step 1422). In one example, the vertices aremoved an infinitesimally small distance in a positive y direction. Thevalues for the 2D edge functions are determined using the moved vertices(step 1424). As explained above, because the value of C is already knownto be zero, this determination can be simplified. Further, as explainedabove, vertices do not need to be moved by any finite amount, butinstead, the sign corresponding to moved vertices can be calculateddirectly from the input values to the DP2 operation.

If moving the triangle vertices along the first axis resolves the signof the 2D edge function (No in step 1426), then a determination is madewhether all of the edge function values are positive or negative (step1418) to determine if the intersection is inside or outside of thetriangle. However, if moving the triangle vertices along the first axisdoes not resolve the sign of the 2D edge function, then the trianglevertices may be conceptually moved along a second axis to resolve thesign of the 2D edge function.

In FIG. 14, if the edge function values still result in a zero in step1426, then the triangle vertices (e.g., transformed triangle vertices instep 1412) are conceptually moved along a second axis of the 2D space1428. In one example, the vertices are moved an infinitesimally smalldistance in a negative x direction. The values for the 2D edge functionsare determined using the moved vertices (step 1430). As explained above,because the value of C is already known to be zero this determinationcan be simplified. Further, as in previous steps 1422 and 1424, thevertices do not need to be moved by any finite amount, but instead, thesign corresponding to moved vertices can be calculated directly from theinput values to the DP2 operation.

If moving the triangle vertices along the second axis resolves the signof the 2D edge function (No in step 1432), then a determination is madewhether all of the edge function values are positive or negative (step1434) to determine if the intersection is inside or outside of thetriangle. If the triangle is determined to be intersected (Yes in step1434), then the intersection for the triangle can be identified (step1420).

If moving the triangle vertices along the second axis does not resolvethe sign of the 2D edge functions (Yes in step 1432), then the twotriangle vertices are equal. In this case an intersection is notreported.

The operations above are similar to rasterization rules in that when oneof the values is exactly zero, the operations effectively adjust thezero to not be zero in one way or another. The sign of the results isdetermined by the values of the operands that go into the DP2 unit.

The single-hit guarantee rules discussed above are not so limited andcan be implemented in other ways by, for example, adopting a differentsign convention, and/or moving vertices along the axes in a differentorder or in different directions. It may be important in someimplementations to use the same convention for testing a given range oftriangles.

In exemplary non-limiting embodiments, the tie-breaking could equally beframed in terms of evaluating the edge function not exactly at theorigin but slightly away from it. In this case, the sign of the edgefunction evaluation would depend on the signs of the edge functionparameters A and B, and the resulting tie-breaking tests would be of theexact same form.

FIG. 15 illustrates ray-triangle test and transform unit 1500 accordingto an exemplary embodiment of this disclosure. The ray-triangle test andtransform unit 1500 is configured to receive ray and triangleinformation and determine whether the ray intersects the triangle. Theray-triangle test and transform unit 1500 includes hardware toaccurately determine intersection at or near edges and/or vertices andincorporates tie-breaking rules to ensure that a single intersection isreturned when the intersection is at or near an edge or vertex shared byother triangles. In an exemplary non-limiting embodiment, theray-triangle test and transform block 720 shown in FIG. 9 may comprisethe components illustrated in FIG. 15.

The ray-triangle test and transform unit 1500 may include a transformand project block 1510, one or more fused floating point operation units1520, 1522, and 1524, and a comparator 1550. The transform and projectblock 1510 receives ray and triangle information and applies geometrictransforms and/or projections to the ray and/or triangle. The transformsand/or projections allow to simplify the intersection problem from a 3Dspace to a 2D space.

The one or more fused floating point operation units 1520, 1522, and1524 are configured to receive transformed ray and triangle informationand perform multiple floating point calculations in a reduced number ofoperations (e.g., one fused floating point operation). The one or morefused floating point operation units 1520, 1522, and 1524 may be a fused2-component dot product unit. In the example shown in FIG. 15, eachfused floating point operation unit receives transformed ray and twotransformed vertices information (e.g., two components for each of thetwo transformed vertices). Based on this information the fused floatingpoint operation units perform the edge tests for each pair or verticesand the ray.

The comparator 1550 is configured to compare the outputs from the fusedfloating point operation units to determine if the triangle is hit ornot hit by the ray. In one example, if all of the values from the fusedfloating point operation units have the same sign (e.g., all negative orpositive), then a hit may be reported. If all of the values from thefused floating point operation units have different signs, then a missmay be reported.

If the outputs from the fused floating point operation units 1520, 1522,1524 include a zero, then the intersection is located at the edge orvertex and tie-breaking rules need to be applied to determine whether toreport an intersection (e.g., a hit or no hit). In one example, thecomparator 1550 may be configured to implement the tie-breaking rules.For example, the comparator 1550 may include logic configured to, uponreceiving a zero from one or more fused floating point operation units1520, 1522, 1524, compare the values of the transformed trianglevertices to determine whether there is a hit for the triangle. As shownin FIG. 15, the comparator 1550 may receive transformed vertices fromthe transform and project block 1510 and compare the transformedvertices to determined, based on the tie-breaking rules, whether thereis a hit or no hit for the specific triangle.

In some example embodiments, the tie-breaking rule may be implemented byinfinitesimally nudging the vertices of the triangle along a first axis(e.g., positive y-axis) and repeating the edge tests to see if a zero isstill output from the fused floating point operation units. If the zerois still output, then the vertices of the triangle can beinfinitesimally nudged along a second axis (e.g., negative x-axis) tosee if the zero is removed from the output of the fused floating pointoperation units. If the zero is no longer output after nudging thetriangle vertices, the signs of the fused floating point operation unitscan be used to determine whether there is a hit. If nudging the trianglevertices does not change the result, no hit may be returned for thetriangle.

FIG. 15 illustrates three fused floating point operation units 1520,1522, 1524. In some exemplary embodiment, a different number of fusedfloating point operation units may be included in the ray-triangle testand transform unit 1500. For example, a single fused floating pointoperation unit may be used to perform multiple computations in series.In some examples, the ray-triangle test and transform unit 1500 may notbe limited to testing intersections with triangles and the number offused floating point operation units used may be based on geometry ofthe primitive (e.g., number of vertices in the primitive).

FIG. 16A illustrates a tie-breaking scheme obtained from following hitpatterns for edges. For example, the tie-breaking scheme includes afirst tie-break test moving the vertices conceptually in a positivey-direction and a second tie-break test moving the vertices conceptuallyin a negative x-direction. In each diagram shown in FIG. 16A, the shadedregion indicates on which side of the edge the origin is considered tolie when it in reality lies exactly on the edge. In the first threecases the situation is resolved by the first tie-break test. The fourthcase is resolved by the second tie-break test.

FIG. 16B illustrates a triangle fan with vertex shared at the origin bya plurality of triangles. If the ray intersects the vertex, a singletriangle should be returned as hit. FIG. 16B illustrates the hitpatterns for a triangle fan with vertex at the origin. The hit patternis determined by applying the first and second tie-break test to theillustrated triangle fan. Applying the first and second tie-break to thenon-shaded triangles will determine that the triangle is notintersected. However, applying the first and second tie-break to theshaded triangle will confirm that the triangle is intersected.

Example Image Generation Pipeline Including Ray Tracing

The ray tracing and other capabilities described above can be used in avariety of ways. For example, in addition to being used to render ascene using ray tracing, they may be implemented in combination withscan conversion techniques such as in the context of scan convertinggeometric building blocks (i.e., polygon primitives such as triangles)of a 3D model for generating image for display (e.g., on display 150illustrated in FIG. 1). FIG. 17 illustrates an example flowchart forprocessing primitives to provide image pixel values of an image, inaccordance with an embodiment.

As FIG. 17 shows, an image of a 3D model may be generated in response toreceiving a user input (Step 1652). The user input may be a request todisplay an image or image sequence, such as an input operation performedduring interaction with an application (e.g., a game application). Inresponse to the user input, the system performs scan conversion andrasterization of 3D model geometric primitives of a scene usingconventional GPU 3D graphics pipeline (Step 1654). The scan conversionand rasterization of geometric primitives may include for exampleprocessing primitives of the 3D model to determine image pixel valuesusing conventional techniques such as lighting, transforms, texturemapping, rasterization and the like as is well known to those skilled inthe art and discussed below in connection with FIG. 21. The generatedpixel data may be written to a frame buffer.

In step 1656, one or more rays may be traced from one or more points onthe rasterized primitives using TTU hardware acceleration. The rays maybe traced in accordance with the one or more ray-tracing capabilitiesdisclosed in this application. Based on the results of the ray tracing,the pixel values stored in the buffer may be modified (Step 1658).Modifying the pixel values may in some applications for example improvethe image quality by, for example, applying more realistic reflectionsand/or shadows. An image is displayed (Step 1660) using the modifiedpixel values stored in the buffer.

In one example, scan conversion and rasterization of geometricprimitives may be implemented using the processing system described inrelation to FIGS. 18-20, 22, 23, 24 and/or 25, and ray tracing may beimplemented by the SM's 132 using the TTU architecture described inrelation to FIG. 9, to add further visualization features (e.g.,specular reflection, shadows, etc.). FIG. 17 is just a non-limitingexample—the SM's 132 could employ the described TTU by itself withouttexture processing or other conventional 3D graphics processing toproduce images, or the SM's could employ texture processing and otherconventional 3D graphics processing without the described TTU to produceimages. The SM's can also implement any desired image generation orother functionality in software depending on the application to provideany desired programmable functionality that is not bound to the hardwareacceleration features provided by texture mapping hardware, treetraversal hardware or other graphics pipeline hardware.

Example Parallel Processing Architecture Including Ray Tracing

The TTU structure described above can be implemented in, or inassociation with, an example non-limiting parallel processing systemarchitecture such as that described below in relation to FIGS. 18-25.Such a parallel processing architecture can be used for example toimplement the GPU 130 of FIG. 1.

Example Parallel Processing Architecture

FIG. 18 illustrates an example non-limiting parallel processing unit(PPU) 1700. In an embodiment, the PPU 1700 is a multi-threaded processorthat is implemented on one or more integrated circuit devices. The PPU1700 is a latency hiding architecture designed to process many threadsin parallel. A thread (i.e., a thread of execution) is an instantiationof a set of instructions configured to be executed by the PPU 1700. Inan embodiment, the PPU 1700 is configured to implement a graphicsrendering pipeline for processing three-dimensional (3D) graphics datain order to generate two-dimensional (2D) image data for display on adisplay device such as a liquid crystal display (LCD) device, an organiclight emitting diode (OLED) device, a transparent light emitting diode(TOLED) device, a field emission display (FEDs), a field sequentialdisplay, a projection display, a head mounted display or any otherdesired display. In other embodiments, the PPU 1700 may be utilized forperforming general-purpose computations. While one exemplary parallelprocessor is provided herein for illustrative purposes, it should benoted that such processor is set forth for illustrative purposes only,and that any processor may be employed to supplement and/or substitutefor the same.

For example, one or more PPUs 1700 may be configured to acceleratethousands of High Performance Computing (HPC), data center, and machinelearning applications. The PPU 1700 may be configured to acceleratenumerous deep learning systems and applications including autonomousvehicle platforms, deep learning, high-accuracy speech, image, and textrecognition systems, intelligent video analytics, molecular simulations,drug discovery, disease diagnosis, weather forecasting, big dataanalytics, astronomy, molecular dynamics simulation, financial modeling,robotics, factory automation, real-time language translation, onlinesearch optimizations, and personalized user recommendations, and thelike.

The PPU 1700 may be included in a desktop computer, a laptop computer, atablet computer, servers, supercomputers, a smart-phone (e.g., awireless, hand-held device), personal digital assistant (PDA), a digitalcamera, a vehicle, a head mounted display, a hand-held electronicdevice, and the like. In an embodiment, the PPU 1700 is embodied on asingle semiconductor substrate. In another embodiment, the PPU 1700 isincluded in a system-on-a-chip (SoC) along with one or more otherdevices such as additional PPUs 1700, the memory 1704, a reducedinstruction set computer (RISC) CPU, a memory management unit (MMU), adigital-to-analog converter (DAC), and the like.

In an embodiment, the PPU 1700 may be included on a graphics card thatincludes one or more memory devices 1704. The graphics card may beconfigured to interface with a PCIe slot on a motherboard of a desktopcomputer. In yet another embodiment, the PPU 1700 may be an integratedgraphics processing unit (iGPU) or parallel processor included in thechipset of the motherboard.

As shown in FIG. 18, the PPU 1700 includes an Input/Output (I/O) unit1705, a front end unit 1715, a scheduler unit 1720, a work distributionunit 1725, a hub 1730, a crossbar (Xbar) 1770, one or more generalprocessing clusters (GPCs) 1750, and one or more partition units 1780.The PPU 1700 may be connected to a host processor or other PPUs 1700 viaone or more high-speed NVLink 1710 interconnect. The PPU 1700 may beconnected to a host processor or other peripheral devices via aninterconnect 1702. The PPU 1700 may also be connected to a local memorycomprising a number of memory devices 1704. In an embodiment, the localmemory may comprise a number of dynamic random access memory (DRAM)devices. The DRAM devices may be configured as a high-bandwidth memory(HBM) subsystem, with multiple DRAM dies stacked within each device.

The NVLink 1710 interconnect enables systems to scale and include one ormore PPUs 1700 combined with one or more CPUs, supports cache coherencebetween the PPUs 1700 and CPUs, and CPU mastering. Data and/or commandsmay be transmitted by the NVLink 1710 through the hub 1730 to/from otherunits of the PPU 1700 such as one or more copy engines, a video encoder,a video decoder, a power management unit, etc. (not explicitly shown).The NVLink 1710 is described in more detail in conjunction with FIG. 24.

The I/O unit 1705 is configured to transmit and receive communications(i.e., commands, data, etc.) from a host processor (not shown) over theinterconnect 1702. The I/O unit 1705 may communicate with the hostprocessor directly via the interconnect 1702 or through one or moreintermediate devices such as a memory bridge. In an embodiment, the I/Ounit 1705 may communicate with one or more other processors, such as oneor more of the PPUs 1700 via the interconnect 1702. In an embodiment,the I/O unit 1705 implements a Peripheral Component Interconnect Express(PCIe) interface for communications over a PCIe bus and the interconnect1702 is a PCIe bus. In alternative embodiments, the I/O unit 1705 mayimplement other types of well-known interfaces for communicating withexternal devices.

The I/O unit 1705 decodes packets received via the interconnect 1702. Inan embodiment, the packets represent commands configured to cause thePPU 1700 to perform various operations. The I/O unit 1705 transmits thedecoded commands to various other units of the PPU 1700 as the commandsmay specify. For example, some commands may be transmitted to the frontend unit 1715. Other commands may be transmitted to the hub 1730 orother units of the PPU 1700 such as one or more copy engines, a videoencoder, a video decoder, a power management unit, etc. (not explicitlyshown). In other words, the I/O unit 1705 is configured to routecommunications between and among the various logical units of the PPU1700.

In an embodiment, a program executed by the host processor encodes acommand stream in a buffer that provides workloads to the PPU 1700 forprocessing. A workload may comprise several instructions and data to beprocessed by those instructions. The buffer is a region in a memory thatis accessible (i.e., read/write) by both the host processor and the PPU1700. For example, the I/O unit 1705 may be configured to access thebuffer in a system memory connected to the interconnect 1702 via memoryrequests transmitted over the interconnect 1702. In an embodiment, thehost processor writes the command stream to the buffer and thentransmits a pointer to the start of the command stream to the PPU 1700.The front end unit 1715 receives pointers to one or more commandstreams. The front end unit 1715 manages the one or more streams,reading commands from the streams and forwarding commands to the variousunits of the PPU 1700.

The front end unit 1715 is coupled to a scheduler unit 1720 thatconfigures the various GPCs 1750 to process tasks defined by the one ormore streams. The scheduler unit 1720 is configured to track stateinformation related to the various tasks managed by the scheduler unit1720. The state may indicate which GPC 1750 a task is assigned to,whether the task is active or inactive, a priority level associated withthe task, and so forth. The scheduler unit 1720 manages the execution ofa plurality of tasks on the one or more GPCs 1750.

The scheduler unit 1720 is coupled to a work distribution unit 1725 thatis configured to dispatch tasks for execution on the GPCs 1750. The workdistribution unit 1725 may track a number of scheduled tasks receivedfrom the scheduler unit 1720. In an embodiment, the work distributionunit 1725 manages a pending task pool and an active task pool for eachof the GPCs 1750. The pending task pool may comprise a number of slots(e.g., 32 slots) that contain tasks assigned to be processed by aparticular GPC 1750. The active task pool may comprise a number of slots(e.g., 4 slots) for tasks that are actively being processed by the GPCs1750. As a GPC 1750 finishes the execution of a task, that task isevicted from the active task pool for the GPC 1750 and one of the othertasks from the pending task pool is selected and scheduled for executionon the GPC 1750. If an active task has been idle on the GPC 1750, suchas while waiting for a data dependency to be resolved, then the activetask may be evicted from the GPC 1750 and returned to the pending taskpool while another task in the pending task pool is selected andscheduled for execution on the GPC 1750.

The work distribution unit 1725 communicates with the one or more GPCs1750 via XBar 1770. The XBar 1770 is an interconnect network thatcouples many of the units of the PPU 1700 to other units of the PPU1700. For example, the XBar 1770 may be configured to couple the workdistribution unit 1725 to a particular GPC 1750. Although not shownexplicitly, one or more other units of the PPU 1700 may also beconnected to the XBar 1770 via the hub 1730.

The tasks are managed by the scheduler unit 1720 and dispatched to a GPC1750 by the work distribution unit 1725. The GPC 1750 is configured toprocess the task and generate results. The results may be consumed byother tasks within the GPC 1750, routed to a different GPC 1750 via theXBar 1770, or stored in the memory 1704. The results can be written tothe memory 1704 via the partition units 1780, which implement a memoryinterface for reading and writing data to/from the memory 1704. Theresults can be transmitted to another PPU 1704 or CPU via the NVLink1710. In an embodiment, the PPU 1700 includes a number U of partitionunits 1780 that is equal to the number of separate and distinct memorydevices 1704 coupled to the PPU 1700. A partition unit 1780 will bedescribed in more detail below in conjunction with FIG. 19.

In an embodiment, a host processor (e.g., processor 120 of FIG. 1)executes a driver kernel that implements an application programminginterface (API) that enables one or more applications executing on thehost processor to schedule operations for execution on the PPU 1700. Inan embodiment, multiple compute applications are simultaneously executedby the PPU 1700 and the PPU 1700 provides isolation, quality of service(QoS), and independent address spaces for the multiple computeapplications. An application may generate instructions (i.e., API calls)that cause the driver kernel to generate one or more tasks for executionby the PPU 1700. The driver kernel outputs tasks to one or more streamsbeing processed by the PPU 1700. Each task may comprise one or moregroups of related threads, referred to herein as a warp. In anembodiment, a warp comprises 32 related threads that may be executed inparallel. Cooperating threads may refer to a plurality of threadsincluding instructions to perform the task and that may exchange datathrough shared memory. Threads and cooperating threads are described inmore detail in conjunction with FIG. 22.

Example Memory Partition Unit

The MMU 1890 provides an interface between the GPC 1750 and thepartition unit 1780. The MMU 1890 may provide translation of virtualaddresses into physical addresses, memory protection, and arbitration ofmemory requests. In an embodiment, the MMU 1890 provides one or moretranslation lookaside buffers (TLBs) for performing translation ofvirtual addresses into physical addresses in the memory 1704.

FIG. 19 illustrates a memory partition unit 1780 of the PPU 1700 of FIG.18, in accordance with an embodiment. As shown in FIG. 19, the memorypartition unit 1780 includes a Raster Operations (ROP) unit 1850, alevel two (L2) cache 1860, and a memory interface 1870. The memoryinterface 1870 is coupled to the memory 1704. Memory interface 1870 mayimplement 32, 64, 128, 1024-bit data buses, or the like, for high-speeddata transfer. In an embodiment, the PPU 1700 incorporates U memoryinterfaces 1870, one memory interface 1870 per pair of partition units1780, where each pair of partition units 1780 is connected to acorresponding memory device 1704. For example, PPU 1700 may be connectedto up to Y memory devices 1704, such as high bandwidth memory stacks orgraphics double-data-rate, version 5, synchronous dynamic random accessmemory, or other types of persistent storage.

In an embodiment, the memory interface 1870 implements an HBM2 memoryinterface and Y equals half U. In an embodiment, the HBM2 memory stacksare located on the same physical package as the PPU 1700, providingsubstantial power and area savings compared with conventional GDDR5SDRAM systems. In an embodiment, each HBM2 stack includes four memorydies and Y equals 4, with HBM2 stack including two 128-bit channels perdie for a total of 8 channels and a data bus width of 1024 bits.

In an embodiment, the memory 1704 supports Single-Error CorrectingDouble-Error Detecting (SECDED) Error Correction Code (ECC) to protectdata. ECC provides higher reliability for compute applications that aresensitive to data corruption. Reliability is especially important inlarge-scale cluster computing environments where PPUs 1700 process verylarge datasets and/or run applications for extended periods.

In an embodiment, the PPU 1700 implements a multi-level memoryhierarchy. In an embodiment, the memory partition unit 1780 supports aunified memory to provide a single unified virtual address space for CPUand PPU 1700 memory, enabling data sharing between virtual memorysystems. In an embodiment the frequency of accesses by a PPU 1700 tomemory located on other processors is traced to ensure that memory pagesare moved to the physical memory of the PPU 1700 that is accessing thepages more frequently. In an embodiment, the NVLink 1710 supportsaddress translation services allowing the PPU 1700 to directly access aCPU's page tables and providing full access to CPU memory by the PPU1700.

In an embodiment, copy engines transfer data between multiple PPUs 1700or between PPUs 1700 and CPUs. The copy engines can generate page faultsfor addresses that are not mapped into the page tables. The memorypartition unit 1780 can then service the page faults, mapping theaddresses into the page table, after which the copy engine can performthe transfer. In a conventional system, memory is pinned (i.e.,non-pageable) for multiple copy engine operations between multipleprocessors, substantially reducing the available memory. With hardwarepage faulting, addresses can be passed to the copy engines withoutworrying if the memory pages are resident, and the copy process istransparent.

Data from the memory 1704 or other system memory may be fetched by thememory partition unit 1780 and stored in the L2 cache 1860, which islocated on-chip and is shared between the various GPCs 1750. As shown,each memory partition unit 1780 includes a portion of the L2 cache 1860associated with a corresponding memory device 1704. Lower level cachesmay then be implemented in various units within the GPCs 1750. Forexample, each of the SMs 1840 may implement a level one (L1) cache. TheL1 cache is private memory that is dedicated to a particular SM 1840.Data from the L2 cache 1860 may be fetched and stored in each of the L1caches for processing in the functional units of the SMs 1840. The L2cache 1860 is coupled to the memory interface 1870 and the XBar 1770.

The ROP unit 1850 performs graphics raster operations related to pixelcolor, such as color compression, pixel blending, and the like. The ROPunit 1850 also implements depth testing in conjunction with the rasterengine 1825, receiving a depth for a sample location associated with apixel fragment from the culling engine of the raster engine 1825. Thedepth is tested against a corresponding depth in a depth buffer for asample location associated with the fragment. If the fragment passes thedepth test for the sample location, then the ROP unit 1850 updates thedepth buffer and transmits a result of the depth test to the rasterengine 1825. It will be appreciated that the number of partition units1780 may be different than the number of GPCs 1750 and, therefore, eachROP unit 1850 may be coupled to each of the GPCs 1750. The ROP unit 1850tracks packets received from the different GPCs 1750 and determineswhich GPC 1750 that a result generated by the ROP unit 1850 is routed tothrough the Xbar 1770. Although the ROP unit 1850 is included within thememory partition unit 1780 in FIG. 19, in other embodiment, the ROP unit1850 may be outside of the memory partition unit 1780. For example, theROP unit 1850 may reside in the GPC 1750 or another unit.

Example General Processing Clusters

FIG. 20 illustrates a GPC 1750 of the PPU 1700 of FIG. 18, in accordancewith an embodiment. As shown in FIG. 20, each GPC 1750 includes a numberof hardware units for processing tasks. In an embodiment, each GPC 1750includes a pipeline manager 1810, a pre-raster operations unit (PROP)1815, a raster engine 1825, a work distribution crossbar (WDX) 1880, amemory management unit (MMU) 1890, and one or more Data ProcessingClusters (DPCs) 1820. It will be appreciated that the GPC 1750 of FIG.20 may include other hardware units in lieu of or in addition to theunits shown in FIG. 20.

In an embodiment, the operation of the GPC 1750 is controlled by thepipeline manager 1810. The pipeline manager 1810 manages theconfiguration of the one or more DPCs 1820 for processing tasksallocated to the GPC 1750. In an embodiment, the pipeline manager 1810may configure at least one of the one or more DPCs 1820 to implement atleast a portion of a graphics rendering pipeline.

Each DPC 1820 included in the GPC 1750 includes an M-Pipe Controller(MPC) 1830, a primitive engine 1835, one or more SMs 1840, one or moreTexture Units 1842, and one or more TTUs 700. The SM 1840 may bestructured similarly to SM 132 described above. The MPC 1830 controlsthe operation of the DPC 1820, routing packets received from thepipeline manager 1810 to the appropriate units in the DPC 1820. Forexample, packets associated with a vertex may be routed to the primitiveengine 1835, which is configured to fetch vertex attributes associatedwith the vertex from the memory 1704. In contrast, packets associatedwith a shader program may be transmitted to the SM 1840.

When configured for general purpose parallel computation, a simplerconfiguration can be used compared with graphics processing.Specifically, the fixed function graphics processing units shown in FIG.18, are bypassed, creating a much simpler programming model. In thegeneral purpose parallel computation configuration, the workdistribution unit 1725 assigns and distributes blocks of threadsdirectly to the DPCs 1820. The threads in a block execute the sameprogram, using a unique thread ID in the calculation to ensure eachthread generates unique results, using the SM 1840 to execute theprogram and perform calculations, shared memory/L1 cache 1970 tocommunicate between threads, and the LSU 1954 to read and write globalmemory through the shared memory/L1 cache 1970 and the memory partitionunit 1780. When configured for general purpose parallel computation, theSM 1840 can also write commands that the scheduler unit 1720 can use tolaunch new work on the DPCs 1820. The TTU 700 can be used to acceleratespatial queries in the context of general purpose computation.

Graphics Rendering Pipeline

A DPC 1820 may be configured to execute a vertex shader program on theprogrammable streaming multiprocessor (SM) 1840 which may acceleratecertain shading operations with TTU 700. The pipeline manager 1810 mayalso be configured to route packets received from the work distributionunit 1725 to the appropriate logical units within the GPC 1750. Forexample, some packets may be routed to fixed function hardware units inthe PROP 1815 and/or raster engine 1825 while other packets may berouted to the DPCs 1820 for processing by the primitive engine 1835 orthe SM 1840. In an embodiment, the pipeline manager 1810 may configureat least one of the one or more DPCs 1820 to implement a neural networkmodel and/or a computing pipeline.

The PROP unit 1815 is configured to route data generated by the rasterengine 1825 and the DPCs 1820 to a Raster Operations (ROP) unit,described in more detail in conjunction with FIG. 19. The PROP unit 1815may also be configured to perform optimizations for color blending,organize pixel data, perform address translations, and the like.

The raster engine 1825 includes a number of fixed function hardwareunits configured to perform various raster operations. In an embodiment,the raster engine 1825 includes a setup engine, a coarse raster engine,a culling engine, a clipping engine, a fine raster engine, and a tilecoalescing engine. The setup engine receives transformed vertices andgenerates plane equations associated with the geometric primitivedefined by the vertices. The plane equations are transmitted to thecoarse raster engine to generate coverage information (e.g., an x,ycoverage mask for a tile) for the primitive. The output of the coarseraster engine is transmitted to the culling engine where fragmentsassociated with the primitive that fail a z-test are culled, andnon-culled fragments are transmitted to a clipping engine wherefragments lying outside a viewing frustum are clipped. Those fragmentsthat survive clipping and culling may be passed to the fine rasterengine to generate attributes for the pixel fragments based on the planeequations generated by the setup engine. The output of the raster engine1825 comprises fragments to be processed, for example, by a fragmentshader implemented within a DPC 1820

In more detail, the PPU 1700 is configured to receive commands thatspecify shader programs for processing graphics data. Graphics data maybe defined as a set of primitives such as points, lines, triangles,quads, triangle strips, and the like. Typically, a primitive includesdata that specifies a number of vertices for the primitive (e.g., in amodel-space coordinate system) as well as attributes associated witheach vertex of the primitive. The PPU 1700 can be configured to processthe graphics primitives to generate a frame buffer (i.e., pixel data foreach of the pixels of the display) using for example TTU 700 as ahardware acceleration resource.

An application writes model data for a scene (i.e., a collection ofvertices and attributes) to a memory such as a system memory or memory1704. The model data defines each of the objects that may be visible ona display. The model data may also define one or more BVH's as describedabove. The application then makes an API call to the driver kernel thatrequests the model data to be rendered and displayed. The driver kernelreads the model data and writes commands to the one or more streams toperform operations to process the model data. The commands may referencedifferent shader programs to be implemented on the SMs 1840 of the PPU1700 including one or more of a vertex shader, hull shader, domainshader, geometry shader, a pixel shader, a ray generation shader, a rayintersection shader, a ray hit shader, and a ray miss shader (thesecorrespond to the shaders defined by the DirectX Raytracing (DXR) API,ignoring any distinction between “closest-hit” and “any-hit” shaders;seehttps://devblogs.nvidia.com/introduction-nvidia-rtx-directx-ray-tracing/).For example, one or more of the SMs 1840 may be configured to execute avertex shader program that processes a number of vertices defined by themodel data. In an embodiment, the different SMs 1840 may be configuredto execute different shader programs concurrently. For example, a firstsubset of SMs 1840 may be configured to execute a vertex shader programwhile a second subset of SMs 1840 may be configured to execute a pixelshader program. The first subset of SMs 1840 processes vertex data toproduce processed vertex data and writes the processed vertex data tothe L2 cache 1860 and/or the memory 1704 (see FIG. 19). After theprocessed vertex data is rasterized (i.e., transformed fromthree-dimensional data into two-dimensional data in screen space) toproduce fragment data, the second subset of SMs 1840 executes a pixelshader to produce processed fragment data, which is then blended withother processed fragment data and written to the frame buffer in memory1704. The vertex shader program and pixel shader program may executeconcurrently, processing different data from the same scene in apipelined fashion until all of the model data for the scene has beenrendered to the frame buffer. Then, the contents of the frame buffer aretransmitted to a display controller for display on a display device.

FIG. 21 is a conceptual diagram of a graphics processing pipeline 2000implemented by the PPU 1700 of FIG. 18. The graphics processing pipeline2000 is an abstract flow diagram of the processing steps implemented togenerate 2D computer-generated images from 3D geometry data. As iswell-known, pipeline architectures may perform long latency operationsmore efficiently by splitting up the operation into a plurality ofstages, where the output of each stage is coupled to the input of thenext successive stage. Thus, the graphics processing pipeline 2000receives input data 2001 that is transmitted from one stage to the nextstage of the graphics processing pipeline 2000 to generate output data2002. In an embodiment, the graphics processing pipeline 2000 mayrepresent a graphics processing pipeline defined by the OpenGL® API. Asan option, the graphics processing pipeline 2000 may be implemented inthe context of the functionality and architecture of the previousFigures and/or any subsequent Figure(s). As discussed above withreference to FIG. 17, the ray tracing may be used to improve the imagequality generated by rasterization of geometric primitives. In someembodiments, ray tracing operations and TTU structure disclosed in thisapplication may be applied to one or more states of the graphicsprocessing pipeline 2000 to improve the subjective image quality.

As shown in FIG. 21, the graphics processing pipeline 2000 comprises apipeline architecture that includes a number of stages. The stagesinclude, but are not limited to, a data assembly stage 2010, a vertexshading stage 2020, a primitive assembly stage 2030, a geometry shadingstage 2040, a viewport scale, cull, and clip (VSCC) stage 2050, arasterization stage 2060, a fragment shading stage 2070, and a rasteroperations stage 2080. In an embodiment, the input data 2001 comprisescommands that configure the processing units to implement the stages ofthe graphics processing pipeline 2000 and geometric primitives (e.g.,points, lines, triangles, quads, triangle strips or fans, etc.) to beprocessed by the stages. The output data 2002 may comprise pixel data(i.e., color data) that is copied into a frame buffer or other type ofsurface data structure in a memory.

The data assembly stage 2010 receives the input data 2001 that specifiesvertex data for high-order surfaces, primitives, or the like. The dataassembly stage 2010 collects the vertex data in a temporary storage orqueue, such as by receiving a command from the host processor thatincludes a pointer to a buffer in memory and reading the vertex datafrom the buffer. The vertex data is then transmitted to the vertexshading stage 2020 for processing.

The vertex shading stage 2020 processes vertex data by performing a setof operations (i.e., a vertex shader or a program) once for each of thevertices. Vertices may be, e.g., specified as a 4-coordinate vector(i.e., <x, y, z, w>) associated with one or more vertex attributes(e.g., color, texture coordinates, surface normal, etc.). The vertexshading stage 2020 may manipulate individual vertex attributes such asposition, color, texture coordinates, and the like. In other words, thevertex shading stage 2020 performs operations on the vertex coordinatesor other vertex attributes associated with a vertex. Such operationscommonly including lighting operations (i.e., modifying color attributesfor a vertex) and transformation operations (i.e., modifying thecoordinate space for a vertex). For example, vertices may be specifiedusing coordinates in an object-coordinate space, which are transformedby multiplying the coordinates by a matrix that translates thecoordinates from the object-coordinate space into a world space or anormalized-device-coordinate (NCD) space. The vertex shading stage 2020generates transformed vertex data that is transmitted to the primitiveassembly stage 2030.

The primitive assembly stage 2030 collects vertices output by the vertexshading stage 2020 and groups the vertices into geometric primitives forprocessing by the geometry shading stage 2040. For example, theprimitive assembly stage 2030 may be configured to group every threeconsecutive vertices as a geometric primitive (i.e., a triangle) fortransmission to the geometry shading stage 2040. In some embodiments,specific vertices may be reused for consecutive geometric primitives(e.g., two consecutive triangles in a triangle strip may share twovertices). The primitive assembly stage 2030 transmits geometricprimitives (i.e., a collection of associated vertices) to the geometryshading stage 2040.

The geometry shading stage 2040 processes geometric primitives byperforming a set of operations (i.e., a geometry shader or program) onthe geometric primitives. Tessellation operations may generate one ormore geometric primitives from each geometric primitive. In other words,the geometry shading stage 2040 may subdivide each geometric primitiveinto a finer mesh of two or more geometric primitives for processing bythe rest of the graphics processing pipeline 2000. The geometry shadingstage 2040 transmits geometric primitives to the viewport SCC stage2050.

In an embodiment, the graphics processing pipeline 2000 may operatewithin a streaming multiprocessor and the vertex shading stage 2020, theprimitive assembly stage 2030, the geometry shading stage 2040, thefragment shading stage 2070, a ray tracing shader, and/orhardware/software associated therewith, may sequentially performprocessing operations. Once the sequential processing operations arecomplete, in an embodiment, the viewport SCC stage 2050 may utilize thedata. In an embodiment, primitive data processed by one or more of thestages in the graphics processing pipeline 2000 may be written to acache (e.g. L1 cache, a vertex cache, etc.). In this case, in anembodiment, the viewport SCC stage 2050 may access the data in thecache. In an embodiment, the viewport SCC stage 2050 and therasterization stage 2060 are implemented as fixed function circuitry.

The viewport SCC stage 2050 performs viewport scaling, culling, andclipping of the geometric primitives. Each surface being rendered to isassociated with an abstract camera position. The camera positionrepresents a location of a viewer looking at the scene and defines aviewing frustum that encloses the objects of the scene. The viewingfrustum may include a viewing plane, a rear plane, and four clippingplanes. Any geometric primitive entirely outside of the viewing frustummay be culled (i.e., discarded) because the geometric primitive will notcontribute to the final rendered scene. Any geometric primitive that ispartially inside the viewing frustum and partially outside the viewingfrustum may be clipped (i.e., transformed into a new geometric primitivethat is enclosed within the viewing frustum. Furthermore, geometricprimitives may each be scaled based on a depth of the viewing frustum.All potentially visible geometric primitives are then transmitted to therasterization stage 2060.

The rasterization stage 2060 converts the 3D geometric primitives into2D fragments (e.g. capable of being utilized for display, etc.). Therasterization stage 2060 may be configured to utilize the vertices ofthe geometric primitives to setup a set of plane equations from whichvarious attributes can be interpolated. The rasterization stage 2060 mayalso compute a coverage mask for a plurality of pixels that indicateswhether one or more sample locations for the pixel intercept thegeometric primitive. In an embodiment, z-testing may also be performedto determine if the geometric primitive is occluded by other geometricprimitives that have already been rasterized. The rasterization stage2060 generates fragment data (i.e., interpolated vertex attributesassociated with a particular sample location for each covered pixel)that are transmitted to the fragment shading stage 2070.

The fragment shading stage 2070 processes fragment data by performing aset of operations (i.e., a fragment shader or a program) on each of thefragments. The fragment shading stage 2070 may generate pixel data(i.e., color values) for the fragment such as by performing lightingoperations or sampling texture maps using interpolated texturecoordinates for the fragment. The fragment shading stage 2070 generatespixel data that is transmitted to the raster operations stage 2080.

The raster operations stage 2080 may perform various operations on thepixel data such as performing alpha tests, stencil tests, and blendingthe pixel data with other pixel data corresponding to other fragmentsassociated with the pixel. When the raster operations stage 2080 hasfinished processing the pixel data (i.e., the output data 2002), thepixel data may be written to a render target such as a frame buffer, acolor buffer, or the like.

It will be appreciated that one or more additional stages may beincluded in the graphics processing pipeline 2000 in addition to or inlieu of one or more of the stages described above. Variousimplementations of the abstract graphics processing pipeline mayimplement different stages. Furthermore, one or more of the stagesdescribed above may be excluded from the graphics processing pipeline insome embodiments (such as the geometry shading stage 2040). Other typesof graphics processing pipelines are contemplated as being within thescope of the present disclosure. Furthermore, any of the stages of thegraphics processing pipeline 2000 may be implemented by one or morededicated hardware units within a graphics processor such as PPU 200.Other stages of the graphics processing pipeline 2000 may be implementedby programmable hardware units such as the SM 1840 of the PPU 1700.

The graphics processing pipeline 2000 may be implemented via anapplication executed by a host processor, such as a CPU 120. In anembodiment, a device driver may implement an application programminginterface (API) that defines various functions that can be utilized byan application in order to generate graphical data for display. Thedevice driver is a software program that includes a plurality ofinstructions that control the operation of the PPU 1700. The APIprovides an abstraction for a programmer that lets a programmer utilizespecialized graphics hardware, such as the PPU 1700, to generate thegraphical data without requiring the programmer to utilize the specificinstruction set for the PPU 1700. The application may include an APIcall that is routed to the device driver for the PPU 1700. The devicedriver interprets the API call and performs various operations torespond to the API call. In some instances, the device driver mayperform operations by executing instructions on the CPU. In otherinstances, the device driver may perform operations, at least in part,by launching operations on the PPU 1700 utilizing an input/outputinterface between the CPU and the PPU 1700. In an embodiment, the devicedriver is configured to implement the graphics processing pipeline 2000utilizing the hardware of the PPU 1700.

Various programs may be executed within the PPU 1700 in order toimplement the various stages of the graphics processing pipeline 2000.For example, the device driver may launch a kernel on the PPU 1700 toperform the vertex shading stage 2020 on one SM 1840 (or multiple SMs1840). The device driver (or the initial kernel executed by the PPU1800) may also launch other kernels on the PPU 1800 to perform otherstages of the graphics processing pipeline 2000, such as the geometryshading stage 2040 and the fragment shading stage 2070. In addition,some of the stages of the graphics processing pipeline 2000 may beimplemented on fixed unit hardware such as a rasterizer or a dataassembler implemented within the PPU 1800. It will be appreciated thatresults from one kernel may be processed by one or more interveningfixed function hardware units before being processed by a subsequentkernel on an SM 1840.

Example Streaming Multiprocessor

The SM 1840 comprises a programmable streaming processor that isconfigured to process tasks represented by a number of threads. Each SM1840 is multi-threaded and configured to execute a plurality of threads(e.g., 32 threads comprising a warp) from a particular group of threadsconcurrently. In an embodiment, the SM 1840 implements a SIMD(Single-Instruction, Multiple-Data) architecture where each thread in agroup of threads (i.e., a warp) is configured to process a different setof data based on the same set of instructions. All threads in the groupof threads execute the same instructions. In another embodiment, the SM1840 implements a SIMT (Single-Instruction, Multiple Thread)architecture where each thread in a group of threads is configured toprocess a different set of data based on the same set of instructions,but where individual threads in the group of threads are allowed todiverge during execution. In an embodiment, a program counter, callstack, and execution state is maintained for each warp, enablingconcurrency between warps and serial execution within warps when threadswithin the warp diverge. In another embodiment, a program counter, callstack, and execution state is maintained for each individual thread,enabling equal concurrency between all threads, within and betweenwarps. When execution state is maintained for each individual thread,threads executing the same instructions may be converged and executed inparallel for maximum efficiency.

FIG. 22 illustrates the streaming multi-processor 1840 of FIG. 20, inaccordance with an embodiment. As shown in FIG. 22, the SM 1840 includesan instruction cache 1905, one or more scheduler units 1910, a registerfile 1920, one or more processing cores 1950, one or more specialfunction units (SFUs) 1952, one or more load/store units (LSUs) 1954, aninterconnect network 1980, a shared memory/L1 cache 1970.

As described above, the work distribution unit 1725 dispatches tasks forexecution on the GPCs 1750 of the PPU 1700. The tasks are allocated to aparticular DPC 1820 within a GPC 1750 and, if the task is associatedwith a shader program, the task may be allocated to an SM 1840. Thescheduler unit 1910 receives the tasks from the work distribution unit1725 and manages instruction scheduling for one or more thread blocksassigned to the SM 1840. The scheduler unit 1910 schedules thread blocksfor execution as warps of parallel threads, where each thread block isallocated at least one warp. In an embodiment, each warp executes 32threads. The scheduler unit 1910 may manage a plurality of differentthread blocks, allocating the warps to the different thread blocks andthen dispatching instructions from the plurality of differentcooperative groups to the various functional units (i.e., cores 1950,SFUs 1952, and LSUs 1954) during each clock cycle.

Cooperative Groups is a programming model for organizing groups ofcommunicating threads that allows developers to express the granularityat which threads are communicating, enabling the expression of richer,more efficient parallel decompositions. Cooperative launch APIs supportsynchronization amongst thread blocks for the execution of parallelalgorithms. Conventional programming models provide a single, simpleconstruct for synchronizing cooperating threads: a barrier across allthreads of a thread block (i.e., the syncthreads( ) function). However,programmers would often like to define groups of threads at smaller thanthread block granularities and synchronize within the defined groups toenable greater performance, design flexibility, and software reuse inthe form of collective group-wide function interfaces.

Cooperative Groups enables programmers to define groups of threadsexplicitly at sub-block (i.e., as small as a single thread) andmulti-block granularities, and to perform collective operations such assynchronization on the threads in a cooperative group. The programmingmodel supports clean composition across software boundaries, so thatlibraries and utility functions can synchronize safely within theirlocal context without having to make assumptions about convergence.Cooperative Groups primitives enable new patterns of cooperativeparallelism, including producer-consumer parallelism, opportunisticparallelism, and global synchronization across an entire grid of threadblocks.

A dispatch unit 1915 is configured to transmit instructions to one ormore of the functional units. In the embodiment, the scheduler unit 1910includes two dispatch units 1915 that enable two different instructionsfrom the same warp to be dispatched during each clock cycle. Inalternative embodiments, each scheduler unit 1910 may include a singledispatch unit 1915 or additional dispatch units 1915.

Each SM 1840 includes a register file 1920 that provides a set ofregisters for the functional units of the SM 1840. In an embodiment, theregister file 1920 is divided between each of the functional units suchthat each functional unit is allocated a dedicated portion of theregister file 1920. In another embodiment, the register file 1920 isdivided between the different warps being executed by the SM 1840. Theregister file 1920 provides temporary storage for operands connected tothe data paths of the functional units. FIG. 23 illustrates an exampleconfiguration of the registers files in the SM 1840.

Each SM 1840 comprises L processing cores 1950. In an embodiment, the SM1840 includes a large number (e.g., 128, etc.) of distinct processingcores 1950. Each core 1950 may include a fully-pipelined,single-precision, double-precision, and/or mixed precision processingunit that includes a floating point arithmetic logic unit and an integerarithmetic logic unit. In an embodiment, the floating point arithmeticlogic units implement the IEEE 754-2008 standard for floating pointarithmetic. In an embodiment, the cores 1950 include 64 single-precision(32-bit) floating point cores, 64 integer cores, 32 double-precision(64-bit) floating point cores, and 8 tensor cores.

Tensor cores are configured to perform matrix operations, and, in anembodiment, one or more tensor cores are included in the cores 1950. Inparticular, the tensor cores are configured to perform deep learningmatrix arithmetic, such as convolution operations for neural networktraining and inferencing. In an embodiment, each tensor core operates ona 4×4 matrix and performs a matrix multiply and accumulate operationD=A×B+C, where A, B, C, and D are 4×4 matrices.

In an embodiment, the matrix multiply inputs A and B are 16-bit floatingpoint matrices, while the accumulation matrices C and D may be 16-bitfloating point or 32-bit floating point matrices. Tensor Cores operateon 16-bit floating point input data with 32-bit floating pointaccumulation. The 16-bit floating point multiply requires 64 operationsand results in a full precision product that is then accumulated using32-bit floating point addition with the other intermediate products fora 4×4×4 matrix multiply. In practice, Tensor Cores are used to performmuch larger two-dimensional or higher dimensional matrix operations,built up from these smaller elements. An API, such as CUDA 9 C++ API,exposes specialized matrix load, matrix multiply and accumulate, andmatrix store operations to efficiently use Tensor Cores from a CUDA-C++program. At the CUDA level, the warp-level interface assumes 16×16 sizematrices spanning all 32 threads of the warp.

Each SM 1840 also comprises M SFUs 1952 that perform special functions(e.g., attribute evaluation, reciprocal square root, and the like). Inan embodiment, the SFUs 1952 may include a tree traversal unitconfigured to traverse a hierarchical tree data structure. In anembodiment, the SFUs 1952 may include texture unit configured to performtexture map filtering operations. In an embodiment, the texture unitsare configured to load texture maps (e.g., a 2D array of texels) fromthe memory 1704 and sample the texture maps to produce sampled texturevalues for use in shader programs executed by the SM 1840. In anembodiment, the texture maps are stored in the shared memory/L1 cache1970. The texture units implement texture operations such as filteringoperations using mip-maps (i.e., texture maps of varying levels ofdetail). In an embodiment, each SM 1740 includes two texture units.

Each SM 1840 also comprises N LSUs 1954 that implement load and storeoperations between the shared memory/L1 cache 1970 and the register file1920. Each SM 1840 includes an interconnect network 1980 that connectseach of the functional units to the register file 1920 and the LSU 1954to the register file 1920, shared memory/L1 cache 1970. In anembodiment, the interconnect network 1980 is a crossbar that can beconfigured to connect any of the functional units to any of theregisters in the register file 1920 and connect the LSUs 1954 to theregister file and memory locations in shared memory/L1 cache 1970.

The shared memory/L1 cache 1970 is an array of on-chip memory thatallows for data storage and communication between the SM 1840 and theprimitive engine 1835 and between threads in the SM 1840. In anembodiment, the shared memory/L1 cache 1970 comprises 128 KB of storagecapacity and is in the path from the SM 1840 to the partition unit 1780.The shared memory/L1 cache 1970 can be used to cache reads and writes.One or more of the shared memory/L1 cache 1970, L2 cache 1860, andmemory 1704 are backing stores.

Combining data cache and shared memory functionality into a singlememory block provides the best overall performance for both types ofmemory accesses. The capacity is usable as a cache by programs that donot use shared memory. For example, if shared memory is configured touse half of the capacity, texture and load/store operations can use theremaining capacity. Integration within the shared memory/L1 cache 1970enables the shared memory/L1 cache 1970 to function as a high-throughputconduit for streaming data while simultaneously providing high-bandwidthand low-latency access to frequently reused data.

FIG. 23 illustrates one example architecture for the SM 1840. Asillustrated in FIG. 20, the SM 1840 may be coupled to one or moreTexture Unit 1842 and/or one or more TTUs 700. As a compromise betweenperformance and area, one example non-limiting embodiment may include asingle Texture Unit 1842 and/or a single TTU 700 per groups of SMs 1840(e.g., See FIG. 20). The TTU 700 may communicate with the SMs 1840 via aTTU input/output block in memory input-output and with a L1 cache via adedicated read interface. In one example embodiment, the TTU 700 onlyreads from the main memory and does not write to the main memory.

Example More Detailed TTU Architecture

As discussed above, the TTU 700 may be a coprocessor to the SM 1840.Like a texture processor, it is exposed via a set of SM instructions,accesses memory as a read-only client of the L1 cache, and returnsresults into the SM register file. Unlike some texture processors, theamount of data that may need to be passed into and out of the TTU 700for a typical query makes it difficult in some embodiments to specifyall the source and destination registers in a single instruction (andbecause most of this data is unique per-thread, there is no TTU analogueof texture headers and samplers). As a consequence, the TTU 700 in someembodiments is programmed via a multi-instruction sequence. Thissequence can be conceptualized as a single “macro-instruction” in someimplementations.

Also like a Texture Units 1842, the TTU 700 in some implementations mayrely on certain read-only data structures in memory that areprepopulated by software. These include:

-   -   One or more BVHs, where each BVH is for example a tree of        axis-aligned bounding boxes, stored in a compressed format that        greatly reduces memory traffic compared to an uncompressed        representation. Each node in the BVH is stored as a complet        structure, with size and alignment in some implementations        matched to that of an L1 cache line. Child complets of a given        parent are preferably stored contiguously in memory and child        pointers are stored in compressed form.    -   Zero or more instance nodes, which provide a way to connect a        leaf of one BVH to the root of another. An instance node may be        a data structure that is also aligned. This structure may        contain a pointer to the sub-BVH, flags that affect back-face        culling behavior in the sub-BVH, and a matrix that corresponds        to the first three rows of an arbitrary transformation matrix        (in homogeneous coordinates) from the coordinate system of the        top-level BVH (commonly “world space”) to that of the sub-BVH        (commonly “object space”). The final row of the matrix in some        embodiments is in some implementations implicitly (0, 0, 0, 1).    -   Zero or more triangle or other primitive buffers, containing for        example triangles stored either as a triplet of coordinates per        vertex or in a lossless compressed format understood by the TTU        700. In addition, an alpha bit may be provided per triangle or        other primitive, indicating triangles that require special        handling by software to determine whether the triangle is        actually intersected by a given ray. Triangle buffers can be        organized into blocks. There may also be a per-triangle        force-no-cull function bit. When set, that bit indicates that        both sides of the triangle should be treated as front-facing or        back-facing with respect to culling, i.e., the triangle should        not be culled because the ray intersects the “back” instead of        the “front”. The simplest use case for this is a single triangle        used to represent a leaf, where we can still see the leaf if the        ray hits it on the back surface.

The TTU 700 in some embodiments is stateless, meaning that noarchitectural state is maintained in the TTU between queries. At thesame time, it is often useful for software running on the SM 1840 torequest continuation of a previous query, which implies that relevantstate should be written to registers by the TTU 700 and then passed backto the TTU in registers (often in-place) to continue. This state maytake the form of a traversal stack that tracks progress in the traversalof the BVH.

A small number of stack initializers may also be provided for beginninga new query of a given type, for example:

-   -   Traversal starting from a complet    -   Intersection of a ray with a range of triangles    -   Intersection of a ray with a range of triangles, followed by        traversal starting from a complet    -   Vertex fetch from a triangle buffer for a given triangle    -   Optional support for instance transforms in front of the        “traversal starting from a complet” and “intersection of a ray        with a range of triangles”.

Vertex fetch is a simple query that may be specified with request datathat consists of a stack initializer and nothing else. Other query typesmay require the specification of a ray or beam, along with the stack orstack initializer and various ray flags describing details of the query.A ray is given by its three-coordinate origin, three-coordinatedirection, and minimum and maximum values for the t-parameter along theray. A beam is additionally given by a second origin and direction.

Various ray flags can be used to control various aspects of traversalbehavior, back-face culling, and handling of the various child nodetypes, subject to a pass/fail status of an optional rayOp test. RayOpsadd considerable flexibility to the capabilities of the TTU. In someexample embodiments, the RayOps portion introduces two Ray Flag versionscan be dynamically selected based on a specified operation on dataconveyed with the ray and data stored in the complet. To explore suchflags, it's first helpful to understand the different types of childnodes allowed within a BVH, as well as the various hit types that theTTU 700 can return to the SM. Example node types are:

-   -   A child complet (i.e., an internal node) By default, the TTU 700        continues traversal by descending into child complets.    -   A triangle range, corresponding to a contiguous set of triangles        within a triangle buffer    -   (1) By default, triangle ranges encountered by a ray are handled        natively by the TTU 700 by testing the triangles for        intersection and shortening the ray accordingly. If traversal        completes and a triangle was hit, default behavior is for the        triangle ID to be returned to SM 1840, along with the t-value        and barycentric coordinates of the intersection. This is the        “Triangle” hit type.    -   (2) By default, intersected triangles with the alpha bit set are        returned to SM 1840 even if traversal has not completed. The        returned traversal stack contains the state required to continue        traversal if software determines that the triangle was in fact        transparent.    -   (3) Triangle intersection in some embodiments is not supported        for beams, so encountered triangle ranges are by default        returned to SM 1840 as a “TriRange” hit type, which includes a        pointer to the first triangle block overlapping the range,        parameters specifying the range, and the t-value of the        intersection with the leaf bounding box.    -   An item range, consisting of an index (derived from a        user-provided “item range base” stored in the complet) and a        count of items.

By default, item ranges are returned to SM 1840 as an “ItemRange” hittype, consisting of for example an index, a count, and the t-value ofthe intersection with the leaf bounding box.

-   -   An instance node.

The TTU 700 in some embodiments can handle one level of instancingnatively by transforming the ray into the coordinate system of theinstance BVH. Additional levels of instancing (or every other level ofinstancing, depending on strategy) may be handled in software. The“InstanceNode” hit type is provided for this purpose, consisting of apointer to the instance node and the tvalue of the intersection with theleaf bounding box. In other implementations, the hardware can handletwo, three or more levels of instancing.

In addition to the node-specific hit types, a generic “NodeRef” hit typeis provided that consists of a pointer to the parent complet itself, aswell as an ID indicating which child was intersected and the t-value ofthe intersection with the bounding box of that child.

An “Error” hit type may be provided for cases where the query or BVH wasimproperly formed or if traversal encountered issues during traversal.

A “None” hit type may be provided for the case where the ray or beammisses all geometry in the scene.

How the TTU handles each of the four possible node types is determinedby a set of node-specific mode flags set as part of the query for agiven ray. The “default” behavior mentioned above corresponds to thecase where the mode flags are set to all zeroes.

Alternative values for the flags allow for culling all nodes of a giventype, returning nodes of a given type to SM as a NodeRef hit type, orreturning triangle ranges or instance nodes to SM using theircorresponding hit types, rather than processing them natively within theTTU 700.

Additional mode flags may be provided for control handling of alphatriangles.

Exemplary Computing System

Systems with multiple GPUs and CPUs are used in a variety of industriesas developers expose and leverage more parallelism in applications suchas artificial intelligence computing. High-performance GPU-acceleratedsystems with tens to many thousands of compute nodes are deployed indata centers, research facilities, and supercomputers to solve everlarger problems. As the number of processing devices within thehigh-performance systems increases, the communication and data transfermechanisms need to scale to support the increased data transmissionbetween the processing devices.

FIG. 24 is a conceptual diagram of a processing system 1900 implementedusing the PPU 1700 of FIG. 18, in accordance with an embodiment. Theexemplary system 1900 may be configured to implement one or more methodsdisclosed in this application. The processing system 1900 includes a CPU1930, switch 1912, and multiple PPUs 1700 each and respective memories1704. The NVLink 1710 provides high-speed communication links betweeneach of the PPUs 1700. Although a particular number of NVLink 1710 andinterconnect 1702 connections are illustrated in FIG. 24, the number ofconnections to each PPU 1700 and the CPU 1930 may vary. The switch 1912interfaces between the interconnect 1702 and the CPU 1930. The PPUs1700, memories 1704, and NVLinks 1710 may be situated on a singlesemiconductor platform to form a parallel processing module 1925. In anembodiment, the switch 1912 supports two or more protocols to interfacebetween various different connections and/or links.

In another embodiment (not shown), the NVLink 1710 provides one or morehigh-speed communication links between each of the PPUs 1700 and the CPU1930 and the switch 1912 interfaces between the interconnect 1702 andeach of the PPUs 1700. The PPUs 1700, memories 1704, and interconnect1702 may be situated on a single semiconductor platform to form aparallel processing module 1925. In yet another embodiment (not shown),the interconnect 1702 provides one or more communication links betweeneach of the PPUs 1700 and the CPU 1930 and the switch 1912 interfacesbetween each of the PPUs 1700 using the NVLink 1710 to provide one ormore high-speed communication links between the PPUs 1700. In anotherembodiment (not shown), the NVLink 1710 provides one or more high-speedcommunication links between the PPUs 1700 and the CPU 1930 through theswitch 1912. In yet another embodiment (not shown), the interconnect1702 provides one or more communication links between each of the PPUs1700 directly. One or more of the NVLink 1710 high-speed communicationlinks may be implemented as a physical NVLink interconnect or either anon-chip or on-die interconnect using the same protocol as the NVLink1710.

In the context of the present description, a single semiconductorplatform may refer to a sole unitary semiconductor-based integratedcircuit fabricated on a die or chip. It should be noted that the termsingle semiconductor platform may also refer to multi-chip modules withincreased connectivity which simulate on-chip operation and makesubstantial improvements over utilizing a conventional busimplementation. Of course, the various circuits or devices may also besituated separately or in various combinations of semiconductorplatforms per the desires of the user. Alternately, the parallelprocessing module 1925 may be implemented as a circuit board substrateand each of the PPUs 1700 and/or memories 1704 may be packaged devices.In an embodiment, the CPU 1930, switch 1912, and the parallel processingmodule 1925 are situated on a single semiconductor platform.

In an embodiment, the signaling rate of each NVLink 1710 is 20 to 25Gigabits/second and each PPU 1700 includes six NVLink 1710 interfaces(as shown in FIG. 24, five NVLink 1710 interfaces are included for eachPPU 1700). Each NVLink 1710 provides a data transfer rate of 25Gigabytes/second in each direction, with six links providing 1700Gigabytes/second. The NVLinks 1710 can be used exclusively forPPU-to-PPU communication as shown in FIG. 24, or some combination ofPPU-to-PPU and PPU-to-CPU, when the CPU 1930 also includes one or moreNVLink 1710 interfaces.

In an embodiment, the NVLink 1710 allows direct load/store/atomic accessfrom the CPU 1930 to each PPU's 1700 memory 1704. In an embodiment, theNVLink 1710 supports coherency operations, allowing data read from thememories 1704 to be stored in the cache hierarchy of the CPU 1930,reducing cache access latency for the CPU 1930. In an embodiment, theNVLink 1710 includes support for Address Translation Services (ATS),allowing the PPU 1700 to directly access page tables within the CPU1930. One or more of the NVLinks 1710 may also be configured to operatein a low-power mode.

FIG. 25 illustrates an exemplary system 1965 in which the variousarchitecture and/or functionality of the various previous embodimentsmay be implemented. The exemplary system 1965 may be configured toimplement one or more methods disclosed in this application.

As shown, a system 1965 is provided including at least one centralprocessing unit 1930 that is connected to a communication bus 1975. Thecommunication bus 1975 may be implemented using any suitable protocol,such as PCI (Peripheral Component Interconnect), PCI-Express, AGP(Accelerated Graphics Port), HyperTransport, or any other bus orpoint-to-point communication protocol(s). The system 1965 also includesa main memory 1940. Control logic (software) and data are stored in themain memory 1940 which may take the form of random access memory (RAM).

The system 1965 also includes input devices 1960, the parallelprocessing system 1925, and display devices 1945, i.e. a conventionalCRT (cathode ray tube), LCD (liquid crystal display), LED (lightemitting diode), plasma display or the like. User input may be receivedfrom the input devices 1960, e.g., keyboard, mouse, touchpad,microphone, and the like. Each of the foregoing modules and/or devicesmay even be situated on a single semiconductor platform to form thesystem 1965. Alternately, the various modules may also be situatedseparately or in various combinations of semiconductor platforms per thedesires of the user.

Further, the system 1965 may be coupled to a network (e.g., atelecommunications network, local area network (LAN), wireless network,wide area network (WAN) such as the Internet, peer-to-peer network,cable network, or the like) through a network interface 1935 forcommunication purposes.

The system 1965 may also include a secondary storage (not shown). Thesecondary storage includes, for example, a hard disk drive and/or aremovable storage drive, representing a floppy disk drive, a magnetictape drive, a compact disk drive, digital versatile disk (DVD) drive,recording device, universal serial bus (USB) flash memory. The removablestorage drive reads from and/or writes to a removable storage unit in awell-known manner.

Computer programs, or computer control logic algorithms, may be storedin the main memory 1940 and/or the secondary storage. Such computerprograms, when executed, enable the system 1965 to perform variousfunctions. The memory 1940, the storage, and/or any other storage arepossible examples of computer-readable media.

The architecture and/or functionality of the various previous figuresmay be implemented in the context of a general computer system, acircuit board system, a game console system dedicated for entertainmentpurposes, an application-specific system, and/or any other desiredsystem. For example, the system 1965 may take the form of a desktopcomputer, a laptop computer, a tablet computer, servers, supercomputers,a smart-phone (e.g., a wireless, hand-held device), personal digitalassistant (PDA), a digital camera, a vehicle, a head mounted display, ahand-held electronic device, a mobile phone device, a television,workstation, game consoles, embedded system, and/or any other type oflogic.

Machine Learning

Deep neural networks (DNNs) developed on processors, such as the PPU1700 have been used for diverse use cases, from self-driving cars tofaster drug development, from automatic image captioning in online imagedatabases to smart real-time language translation in video chatapplications. Deep learning is a technique that models the neurallearning process of the human brain, continually learning, continuallygetting smarter, and delivering more accurate results more quickly overtime. A child is initially taught by an adult to correctly identify andclassify various shapes, eventually being able to identify shapeswithout any coaching. Similarly, a deep learning or neural learningsystem needs to be trained in object recognition and classification forit get smarter and more efficient at identifying basic objects, occludedobjects, etc., while also assigning context to objects.

At the simplest level, neurons in the human brain look at various inputsthat are received, importance levels are assigned to each of theseinputs, and output is passed on to other neurons to act upon. Anartificial neuron or perceptron is the most basic model of a neuralnetwork. In one example, a perceptron may receive one or more inputsthat represent various features of an object that the perceptron isbeing trained to recognize and classify, and each of these features isassigned a certain weight based on the importance of that feature indefining the shape of an object.

A deep neural network (DNN) model includes multiple layers of manyconnected perceptrons (e.g., nodes) that can be trained with enormousamounts of input data to quickly solve complex problems with highaccuracy. In one example, a first layer of the DLL model breaks down aninput image of an automobile into various sections and looks for basicpatterns such as lines and angles. The second layer assembles the linesto look for higher level patterns such as wheels, windshields, andmirrors. The next layer identifies the type of vehicle, and the finalfew layers generate a label for the input image, identifying the modelof a specific automobile brand.

Once the DNN is trained, the DNN can be deployed and used to identifyand classify objects or patterns in a process known as inference.Examples of inference (the process through which a DNN extracts usefulinformation from a given input) include identifying handwritten numberson checks deposited into ATM machines, identifying images of friends inphotos, delivering movie recommendations to over fifty million users,identifying and classifying different types of automobiles, pedestrians,and road hazards in driverless cars, or translating human speech inreal-time.

During training, data flows through the DNN in a forward propagationphase until a prediction is produced that indicates a labelcorresponding to the input. If the neural network does not correctlylabel the input, then errors between the correct label and the predictedlabel are analyzed, and the weights are adjusted for each feature duringa backward propagation phase until the DNN correctly labels the inputand other inputs in a training dataset. Training complex neural networksrequires massive amounts of parallel computing performance, includingfloating-point multiplications and additions that are supported by thePPU 1700. Inferencing is less compute-intensive than training, being alatency-sensitive process where a trained neural network is applied tonew inputs it has not seen before to classify images, translate speech,and generally infer new information.

Neural networks rely heavily on matrix math operations, and complexmulti-layered networks require tremendous amounts of floating-pointperformance and bandwidth for both efficiency and speed. With thousandsof processing cores, optimized for matrix math operations, anddelivering tens to hundreds of TFLOPS of performance, the PPU 1700 is acomputing platform capable of delivering performance required for deepneural network-based artificial intelligence and machine learningapplications.

All patents & publications cited above are incorporated by reference asif expressly set forth.

While the invention has been described in connection with what ispresently considered to be the most practical and preferred embodiments,it is to be understood that the invention is not to be limited to thedisclosed embodiments, but on the contrary, is intended to cover variousmodifications and equivalent arrangements included within the spirit andscope of the appended claims.

The invention claimed is:
 1. A system including: memory that stores atleast a portion of an acceleration data structure including a pluralityof hierarchical nodes, at least one node identifying a primitive rangeof a virtual scene; and hardware circuitry operatively coupled to thememory and configured to: determine intersections between a ray definedin a ray coordinate space and primitives in the primitive range; andwhen the ray is determined to intersect an edge or vertex shared by Nprimitives, where N>1, select less than N primitives to report based ona tie-breaking rule that compares vertex values of vertices shared bythe N primitives in the ray coordinate space.
 2. The system of claim 1,wherein the primitives include triangles and determining intersectionsbetween the ray and the triangles includes, for each triangle:transforming triangle vertices into the ray coordinate space;determining edge function values of post-transform triangle edgesdefined by transformed triangle vertices; if all edge function valuesare nonzero and have a same sign, identifying the triangle as beingintersected by the ray; and if one or more of the edge function valuesis zero, determining whether the triangle is intersected based onwhether another triangle shares the triangle vertices and whether one ormore edge function values of the other triangle are zero.
 3. The systemof claim 1, wherein the hardware circuitry includes a fused floatingpoint operation unit configured to combine multiple floating-pointarithmetic operations to determine intersections between the ray and theprimitives.
 4. The system of claim 3, wherein the fused floating pointoperation unit is configured to perform arithmetic operations usingsingle precision floating-point format.
 5. The system of claim 3,wherein the fused floating point operation unit is configured to performarithmetic operations with expanded 10-bit exponent range.
 6. The systemof claim 1, wherein the hardware circuitry is configured to determineprimitives in the primitive range received from the memory which areintersected by the ray without using double-precision floating-pointarithmetic.
 7. A system including: memory that stores at least a portionof an acceleration data structure including a plurality of hierarchicalnodes, at least one node identifying a primitive range of a virtualscene; and hardware circuitry operatively coupled to the memory andcomprising: projection circuitry configured to project vertex values ofprimitives in the primitive range received from the memory into a 2Dcoordinate space of a ray; and intersection test circuitry coupled tothe projection circuitry and configured to determine intersectionsbetween the ray and primitives in the primitive range based on theprojected vertex values and to report, when the ray is determined tointersect an edge or vertex shared by a plurality of primitives, asingle primitive of the plurality of primitives based on a comparison ofthe projected vertex values of the plurality of primitives.
 8. Thesystem of claim 7, wherein the intersection test circuitry includes aplurality of fused floating point operation units configured to combinemultiple floating-point arithmetic operations used to determineprimitives in the primitive range intersected by the ray.
 9. The systemof claim 8, wherein the fused floating point operation unit isconfigured to perform arithmetic operations with expanded 10-bitexponent range.
 10. A tree traversal unit comprising: ray-surfacetesting hardware configured to test whether a ray intersects pluralgeometric surfaces arranged in 3D space; and tie breaking hardwareconfigured to report a single surface from multiple geometric surfacesbased on a comparison of vertex values of the multiple geometricsurfaces projected into a two-dimensional coordinate space, when theray-surface testing hardware determines the ray intersects each of themultiple geometric surfaces at an edge or vertex shared by the multiplegeometric surfaces.
 11. The tree traversal unit of claim 10, whereinray-surface testing hardware is configured to receive, from a processor,a query including ray information and information about a boundingvolume hierarchy, traverse the bounding volume hierarchy to determine abounding volume within said bounding volume hierarchy the rayintersects, and test intersection between the ray and the pluralgeometric surfaces associated with the bounding volume intersected bythe ray.
 12. The tree traversal unit of claim 10, wherein theray-surface testing hardware includes a spatial transformer thatprojects the plural geometric surfaces onto a plane for ray intersectiontesting.
 13. A tree traversal unit comprising hardware circuitryconfigured to: receive, from a processor, instructions to testintersections between a ray and a plurality of primitives; determine,using an arithmetic unit, whether the ray going through a surface formedby the plurality of primitives intersects an edge or vertex shared by Nprimitives, N>1; and when the ray is determined to intersect the edge orvertex shared by N primitives, push intersection information for lessthan N primitives sharing the edge or vertex onto a stack based oncomparing vertex locations of vertices shared by the N primitives andtransformed into a two-dimensional coordinate space; and report, to theprocessor, intersection information in the stack.
 14. The tree traversalunit of claim 13, wherein when the ray is determined to intersect theedge or vertex shared by the N primitives, intersection information fora single primitive of the N primitives is push onto the stack.
 15. Thetree traversal unit of claim 13, wherein the hardware circuitry isfurther configured to, when the ray is determined to intersect the edgeor vertex of a primitive not shared by another primitive, push onto thestack intersection information for the intersected primitive.
 16. Thetree traversal unit of claim 13, wherein the hardware circuitry isfurther configured to, when the ray is determined to intersect aprimitive not on an edge or vertex, push onto the stack intersectioninformation for the intersected primitive.
 17. The tree traversal unitof claim 13, wherein the intersection information for less than Nprimitives from the N primitives is determined based on a tie-breakingrule that compares vertex values of vertices shared by the N primitivestransformed into ray coordinate space.
 18. The tree traversal unit ofclaim 13, wherein the arithmetic unit includes a fused floating pointoperation unit configured to combine multiple floating-point arithmeticoperations used in determining whether the ray goes through a surfaceformed by the plurality of primitives.
 19. The tree traversal unit ofclaim 13, wherein the arithmetic unit is configured to performarithmetic operations with expanded 10-bit exponent range.